Apr. 15th, 2015

rmd: (wtfdog)
So, I'm mucking around with python - in particular, with F5's "bigsuds" library, which does web transactions with their "iControl" API. I've run into a data structure that is making me remember that I never took a data structures class.

I'm trying to get the list of health monitors for a given pool, using "LocalLB.Pool.get_monitor_instance([pool])". The get_monitor_instance API reference page just says I get a string back. Which, I do, but in python-speak, I get what looks like a dictionary which includes other dictionaries embedded in a list embedded in a list. Like this:

[[{'enabled_state': True, 'instance': {'template_name': 'http', 'instance_definition': {'ipport': {'port': 80, 'address': '10.10.10.23'}, 'address_type': 'ATYPE_EXPLICIT_ADDRESS_EXPLICIT_PORT'}}, 'instance_state': 'INSTANCE_STATE_UP'}, {'enabled_state': True, 'instance': {'template_name': 'http', 'instance_definition': {'ipport': {'port': 80, 'address': '10.10.10.24'}, 'address_type': 'ATYPE_EXPLICIT_ADDRESS_EXPLICIT_PORT'}}, 'instance_state': 'INSTANCE_STATE_UP'}]]


How the heck do I parse this? I'd like to be able to break it down to a dictionary so I can say "print thing["10.10.0.23"]['template_name']" where that would be "http", I guess.

ETA: based on the consensus, evidently by parsing it as JSON. ("Riiiiiiiiiight. What's a cubit JSON?)" Next on my agenda, figuring out wtf this JSON thing is all about.

Profile

rmd: (Default)
rmd

June 2025

S M T W T F S
1234567
89 1011121314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 17th, 2025 02:27 pm
Powered by Dreamwidth Studios