Created
April 23, 2015 18:16
-
-
Save jeffbrl/d68a27fff989d404f1b6 to your computer and use it in GitHub Desktop.
Pyez parsing lxml Element example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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