Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology

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.

Rate this Question
Comments on this Question
Comment made 04-Oct-2017 by jmarter 11

no one has an answer to this?


Answers to this Question


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():

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.

<pre>`>>> import urllib3
>>> from f5.bigip import ManagementRoot
>>> from f5.bigip.contexts import TransactionContextManager
>>> urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
>>> mgmt = ManagementRoot('<host_ip>', '<user>', '<password>')
>>> my_virtual = mgmt.tm.ltm.virtuals.virtual.create(partition='Common', name='sdk-test', destination='')
>>> for profile in my_virtual.profiles_s.get_collection():
...     print(profile.name)
>>> 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)

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

Comments on this Answer
Comment made 11-Oct-2017 by jmarter 11

I didn't have any issues showing the profiles just when trying to bind existing ones to a new VIP. Didn't know I needed a transaction and appreciate your reply/explanation. I think it gets me going on the right path. However I am having problems finding documentation for TransactionContextManager and don't know what to do with 'api:'

with TransactionContextManager(tx) as api: print(api.???)

Comment made 12-Oct-2017 by Ed Summers 1106

I just found an error in the code snippet I posted above due to my copy/paste error in giving you clean output. If you made it to the reference link I posted, the object instance is shown at the bottom of the article:

tx = mgmt.tm.transactions.transaction

I'm not near my lab or notes now but will try to confirm this was the line when I can. I'll edit the answer to include this line in the snippet.

I only used the context manager to perform the transaction, and I never used the 'api' label after assigning it. Looking at the code would probably reveal what you could get from that label or someone with more knowledge may chime in. For my simple example I just added the code that needed to be processed as a transaction, which in this case was anything dealing with profile changes that needed to be done in a way to keep the device in a valid state. I'm new to context managers in Python so at this time really pushing the "I Believe" button.

Hope this helps get you started. It's a bit of an assumption on my part that this would help address the specific issue you were having. Set up the context manager as shown then put whatever lines you need to add/change profiles inside it.

Comment made 16-Oct-2017 by jmarter 11

Thanks again for responding. I'm still not seeing a way to add an existing profile to a new VIP. I can check what's been applied and create new profiles, but I can't really do anything else with those objects. I find it really odd this isn't just a 'whatever.update() method.I figured once I load a VIP I should be able to adjust it.