Forum Discussion
Steve_Brown_882
Jul 01, 2009Historic F5 Account
pycontrol help
Hi Guys,
I am pretty new to python and pycontrol and need a little help with a script I am working on. I think I am missibng something obvious and this may even be more a case of me not fully understanding pyton yet. Any how I would like to have my script return a list of virtual servers, destination IP and destination port. Here is a snippet of my current code which works, but does not return exactly what I am lookign for.
virtual = b.LocalLB_VirtualServer
for vName in virtual.get_list()['return']:
vDest = virtual.get_destination(virtual_servers = [vName])['return']
print vName, vDest
The output looks like this....
vipname [{'port': 443, 'address': '10.1.2.3'}
And I want it to look like...I assume I need to pull the port: and address out of the return, but I have not been able to figure out how.
vipname 443 10.1.2.3
- Steve_Brown_882Historic F5 AccountJust wanted to add the solution since I just figured it out.
- Thanks for posting your update! I'm very weak on my python skills so this will be a good reference to point folks to.
- L4L7_53191
Nimbostratus
Good post, thanks for sharing. Here's another method: it looks like you're calling the iControl portal for each virtual server name separately. iControl and Python's zip() function can save you (and the BigIP!) some time and CPU cycles:In [16]: vlist = b.LocalLB_VirtualServer.get_list()['return'] In [18]: vdest = b.LocalLB_VirtualServer.get_destination(virtual_servers = vlist)['return'] In [19]: combined = zip(vlist, vdest) In [20]: for x in combined: ....: print "%s=>%s:%d" % (x[0], x[1]['address'], x[1]['port'])
- Steve_Brown_882Historic F5 AccountThanks for the input Matt. I have incorporated some of you suggestions and it sure runs faster. I also changed the prints because my ultimate goal was to create a CSV to help us create some documentation. Here is the newest version in case anyone wants to see. I am sure it is not the cleanest code but it is still a work in progress.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects