|
| 1 | +from ncclient import manager |
| 2 | +from pprint import pprint |
| 3 | +import xmltodict |
| 4 | +import xml.dom.minidom |
| 5 | +switch = {"host": "10.10.10.150", "port": "830", |
| 6 | + "username": "root", "password": ""} |
| 7 | + |
| 8 | +#rpc_filter = "<get-interface-information><interface-name>ge-0/0/1</interface-name><detail/></get-interface-information>" |
| 9 | +rpc_filter = "<get-interface-information><terse/></get-interface-information>" |
| 10 | + |
| 11 | +with manager.connect(host=switch["host"], port=switch["port"], username=switch["username"], password=switch["password"], hostkey_verify=False, device_params={"name": "junos"}) as m: |
| 12 | + for capability in m.server_capabilities: |
| 13 | + print('*' * 50) |
| 14 | + print(capability) |
| 15 | + # get the running config on the filtered out interface |
| 16 | + print('Connected') |
| 17 | + netconf_response = m.rpc(rpc_filter) |
| 18 | + print('getting interface details') |
| 19 | + # print(netconf_response) |
| 20 | + interface_name = netconf_response.xpath('//physical-interface/name') |
| 21 | + interface_status = netconf_response.xpath( |
| 22 | + '//physical-interface/oper-status') |
| 23 | + int_admin = netconf_response.xpath('//physical-interface/admin-status') |
| 24 | + logical_name = netconf_response.xpath( |
| 25 | + '//physical-interface/logical-interface/name') |
| 26 | + local_address = netconf_response.xpath( |
| 27 | + '//physical-interface/logical-interface/address-family/interface-address/ifa-local') |
| 28 | + |
| 29 | + for ph_name, status, admin, l_name in zip(interface_name, interface_status, int_admin, logical_name): |
| 30 | + ph_name = ph_name.text.split('\n')[1] |
| 31 | + status = status.text.split('\n')[1] |
| 32 | + admin = admin.text.split('\n')[1] |
| 33 | + l_name = l_name.text.split('\n')[1] |
| 34 | + |
| 35 | + print(f"{ph_name} , {status} , {admin} , {l_name}") |
0 commit comments