How to get interfaces status with Netconf via ncclient

1.9k views Asked by At

I am using ncclient to get information from a router (IOS-XR), however I am not able to get the status. I mean, If I run from the router the command "Show interfaces description" I can see the interface, status, protocol and description. I want to do the same with Netconf using ncclient. Anyone have any idea how to do it? I have tried with get_config and I can get the description but not the status(up, down,admin-down) and protocol (up, down,admin-down)

Thanks

2

There are 2 answers

0
quality-gate On

The Netconf protocol distinguishes between configuration and operational data. In order to retrieve operational data like e.g. the interface status you have to use the get operation instead of the get-config operation.

According to RFC 6241:
get-config is used to "Retrieve all or part of a specified configuration datastore." (config data only)
get is used to "Retrieve running configuration and device state information." (config + oper data)

Whether a node stores configuration or operational data depends on how it is defined in the corresponding YANG module. A node can ether be config false or config true (default)

0
Sachin On

You can try this to get interface details.

from ncclient import manager
from pprint import pprint
import xmltodict
import xml.dom.minidom

router = {
   'ip': '172.30.1.100',
   'port': '830',
   'username': 'test123',
   'password': 'test123'
}

m = manager.connect(host=router['ip'], port=router['port'], username=router['username'],
                    password=router['password'],device_params={'name':'iosxr'} ,hostkey_verify=False)

netconf_filter = """
<filter>
    <interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"/>
</filter>

"""
running_config = m.get(netconf_filter)

print(running_config)
running_config_xml = xmltodict.parse(running_config.xml)["rpc-reply"]["data"]
print(xml.dom.minidom.parseString(str(running_config)).toprettyxml())