Forum Discussion
Adding Client, Server, and SSL profiles to a VIP via the SDK
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
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com