F5 is upgrading its customer support chat feature on My.F5.com. Chat support will be unavailable from 6am-10am PST on 1/20/26. Refer to K000159584 for details.

Forum Discussion

Kurt_Kite_11866's avatar
Kurt_Kite_11866
Icon for Nimbostratus rankNimbostratus
Jan 20, 2017

Python SDK Assign iRules to a virtual server

Hi,

 

I am able to create a virtual using the F5 python SDK including the assignment of HTTP, OneConnect, Client SSL Profiles, and Server SSL profiles. However, I have not been able to figure out how to assign iRules to the virtual server. Does anyone have an example they can share?

 

9 Replies

  • Hi Kurt, The rules are a list, so you would do it this way:

    >>> vip = b.tm.ltm.virtuals.virtual.load(name='testvip')
    >>>vip.rules
    [u'/Common/tcptest'] 
    >>> vip.rules = ['/Common/tcptest', '/Common/platform_info']
    >>> vip.update()
    >>vip.rules
    [u'/Common/tcptest', u'/Common/platform_info']
    

    I did an absolute update on the rules attribute, but I could have also just appended with:

    vip.rules.append('/Common/platform_info')

  • Hi Jason, Thanks very much! This worked for me. I assume that it is not possible to define the rules list as a parameter in the bigip.ltm.virtuals.virtual.create method.

     

    Best Regards, Kurt

     

    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin

      sure, you can do that as well:

      x = b.tm.ltm.virtuals.virtual.create(
         name='testvip5', 
         partition='Common', 
         rules=['/Common/tcptest'], 
         profiles=['/Common/http'])
      
    • IRONMAN_183357's avatar
      IRONMAN_183357
      Icon for Nimbostratus rankNimbostratus

      Hi Jason,

       

      I am getting below error

       

      Traceback (most recent call last): File "C:\Users\krissara\Desktop\F5 SDK\Stage5\VIP add.py", line 6, in x = b.tm.ltm.virtuals.virtual.create( NameError: name 'b' is not defined

       

    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin

      did you instantiate your BIG-IP to b or a different variable first?

      from f5.bigip import ManagementRoot
      b = ManagementRoot('x.x.x.x', 'admin', 'admin')
      
      x = b.tm.ltm.virtuals.virtual.create(
         name='testvip5', 
         partition='Common', 
         rules=['/Common/tcptest'], 
         profiles=['/Common/http'])
      
  • Hi All,

     

    When i try to make connection with F5 box via python, i am getting below error. I am not good in python, please tell me how to proceed this commands with API to create objects in F5

     

    from import ManagementRoot bigip = ManagementRoot('35.154.69.72', 'admin', 'admin')

     

    Warning (from warnings module): File "C:\Users\krissara\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 858 InsecureRequestWarning)InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.htmlssl-warnings

     

    I decided to add urllib3 to avoid cert errors, but not working

     

    urllib3.disable_warnings() Traceback (most recent call last): File "", line 1, in urllib3.disable_warnings() NameError: name 'urllib3' is not defined import urllib3 bigip = ManagementRoot('35.154.69.72', 'admin', 'admin')

     

     

    Warning (from warnings module): File "C:\Users\krissara\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\connectionpool.py", line 858 InsecureRequestWarning) InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.htmlssl-warnings