Skip to content

Instantly share code, notes, and snippets.

@jeffbrl
Created April 23, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffbrl/d68a27fff989d404f1b6 to your computer and use it in GitHub Desktop.
Save jeffbrl/d68a27fff989d404f1b6 to your computer and use it in GitHub Desktop.
Pyez parsing lxml Element example
#!/usr/bin/env python
from jnpr.junos import Device
def build_dict(xml):
jflow = {}
# 1st entry in xml is <inline_jflow_flow_information>
inline_jflow_flow_information = xml[0]
for element in inline_jflow_flow_information:
tag = element.tag.strip('\n')
text = element.text.strip('\n')
jflow[tag] = text
return jflow
dev = Device(host='router', user='username', password='pass' )
dev.open(gather_facts=False)
xml_response = (
dev.rpc.get_service_accounting_status_inline_jflow_flow_information(inline_jflow_flow_information='0')
)
jflow = build_dict(xml_response)
for key, value in jflow.iteritems():
print "{}: {}".format(key, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment