Forum Discussion

jmarter_319029's avatar
jmarter_319029
Icon for Nimbostratus rankNimbostratus
Sep 26, 2017

Adding Client, Server, and SSL profiles to a VIP via the SDK

I've been able to successfully build out a VIP, pool, and nodes then bind them all together using the f5-sdk however I'm running into issues with adding profiles to the VIP's. I'm using the following code to try and update an existing VIP with an existing profile:

 

mgmt = ManagementRoot("x.x.x.x", "username", "password") vip_resource = mgmt.tm.ltm.virtuals.virtual.load(partition='CDE-DMZ', name='test_vip-https-443')

 

for profile in vip_resource.profiles_s.get_collection(): print(profile)

 

Anyone else bang their head over this issue? I can see profiles attached via the GUI but I can't get them to work via the SDK. Any help would be appreciated.

 

  • Are you getting an error from your code when trying to list the profiles, or just not the output you expect? Try the below which will list the profile names:

     

    mgmt = ManagementRoot("x.x.x.x", "username", "password")
    vip_resource = mgmt.tm.ltm.virtuals.virtual.load(partition='CDE-DMZ', name='test_vip-https-443')
    for profile in vip_resource.profiles_s.get_collection():
        print(profile.name)
    `
    
    For adding/modifying profiles I recently found that a transaction may be required to accomplish the change. Here's a sample test I put together when learning about the transaction process. I swapped out the *fastL4* profile for *tcp* + *http* as an example.
    
    `>>> import urllib3
    >>> from f5.bigip import ManagementRoot
    >>> from f5.bigip.contexts import TransactionContextManager
    >>> 
    >>> urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    >>> 
    >>> mgmt = ManagementRoot('', '', '')
    >>> 
    >>> my_virtual = mgmt.tm.ltm.virtuals.virtual.create(partition='Common', name='sdk-test', destination='10.1.0.1:443')
    >>> for profile in my_virtual.profiles_s.get_collection():
    ...     print(profile.name)
    ... 
    fastL4
    >>> tx = mgmt.tm.transactions.transaction
    >>> with TransactionContextManager(tx) as api:
    ...     p_old = my_virtual.profiles_s.profiles.load(partition='Common', name='fastL4')
    ...     p_old.delete() 
    ...     p0 = my_virtual.profiles_s.profiles.create(partition='Common', name='tcp') 
    ...     p1 = my_virtual.profiles_s.profiles.create(partition='Common', name='http')
    ...     my_virtual.ipProtocol = 'tcp'
    ...     my_virtual.update()
    ... 
    >>> 
    >>> for profile in my_virtual.profiles_s.get_collection():
    ...     print(profile.name)
    ... 
    http
    tcp
    >>> 

    I suspect without using the transaction, the individual requests would put the object in an illegal state (the virtual server must have a base profile applied, but the tcp and fastL4 profiles are mutually exclusive).

     

    Hope this helps - let me know. This code is just an example for learning a bit about transactions but I welcome any feedback if there are issues.

     

    Ref: Demystifying iControl REST Part 7