-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse_xml_output.py
47 lines (38 loc) · 1.71 KB
/
parse_xml_output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from ncclient import manager
eos=manager.connect(host="10.73.1.105", port="830", timeout=30, username="arista", password="arista", hostkey_verify=False)
# Configure an interface description
Interface_Ethernet3_description='''
<config xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
<interfaces xmlns="http://openconfig.net/yang/interfaces">
<interface>
<name>Ethernet3</name>
<config>
<description nc:operation="replace">This is the best interface</description>
</config>
</interface>
</interfaces>
</config>
'''
reply = eos.edit_config(target="running", config=Interface_Ethernet3_description, default_operation="none")
# Get interface state and configuration data
Interface_Ethernet3='''
<interfaces>
<interface>
<name>Ethernet3</name>
</interface>
</interfaces>
'''
get_interface_ethernet3 = eos.get(filter=("subtree", Interface_Ethernet3))
print (get_interface_ethernet3)
# Parse the XML output
ns = {None: 'http://openconfig.net/yang/interfaces'}
description = get_interface_ethernet3.data.find(".//interfaces/interface/config/description", namespaces=ns)
print(description.text)
operStatus = get_interface_ethernet3.data.find(".//interfaces/interface/state/oper-status", namespaces=ns)
print(operStatus.text)
# Get interface configuration and parse the XML output
get_interface_ethernet3 = eos.get_config(source="running", filter=("subtree", Interface_Ethernet3))
print (get_interface_ethernet3)
ns = {None: 'http://openconfig.net/yang/interfaces'}
description = get_interface_ethernet3.data.find(".//interfaces/interface/config/description", namespaces=ns)
print(description.text)