Forum Discussion
Ed_Summers
Nimbostratus
Jan 19, 2017F5 Python SDK: How to get virtual server availability?
Due to my limited Python and SDK experience I am finding it difficult to easily obtain the availability state of a virtual server. Given a 'virtual' object, what is the best/easiest way to return the...
Hannes_Rapp
Nimbostratus
Jan 19, 2017Great to see more people opting to use the SDK!
You can work with the output normally, as with any dict-type, using
dict.get('something'). Add in a set of square-brackets, if the extracted value is yet another key-value pair, and if you're looking for a very specific match: dict.get('something')['something'].
Note: In the for-loop, I'm using
virtual.name - this extraction works without use of .get('name') because 'name' is a 1st-level extraction - no nesting is involved. For the same reason, I can do state = stats.entries... in my function, instead of state = stats.get('entries')...
f5-sdk v2.2.0 ; py3.4.3 ; 11.5.4
from f5.bigip import ManagementRoot
def get_vs_state(vs_name):
virtual_s = API_ROOT.tm.ltm.virtuals.virtual.load(name=vs_name)
stats = virtual_s.stats.load()
state = stats.entries.get('status.availabilityState')['description']
return state
API_ROOT = ManagementRoot("bip-01", "admin", "admin")
VIRTUALS = API_ROOT.tm.ltm.virtuals.get_collection()
EXAMPLE OF USE:
Print AvailabilityState of all Virtual Servers
for virtual in VIRTUALS:
print("Name: '%s' AvailabilityState: '%s'" % (virtual.name, get_vs_state(virtual.name)))
Hannes_Rapp
Nimbostratus
Jan 19, 2017Code was tested on BigIP 11.5.4. Will update answer for 12.1.1 in 15 min.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
