Unable to get the complete running config using netconf-yang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024
10:08 AM
- last edited on
03-15-2024
10:25 AM
by
rupeshah
I have a cisco Cisco IOS XE Software, Version 17.03.05 on cisco ASR1001-HX (1SR) processor
I am running this simple netconf yang code to get the runninmg config
import xmltodict
import xml.dom.minidom
from ncclient import manager
router = {
'ip': '192.1168.100.221',
'port': '830',
'username': 'admin',
'password': 'XXXXXXXXXXXX'
}
m = manager.connect(host=router['ip'], port=router['port'], username=router['username'],
password=router['password'],device_params={'name':'iosxe'} ,hostkey_verify=False)
running_config = m.get_config("running").xml
print(xml.dom.minidom.parseString(running_config).toprettyxml())
m.close_session()
I get the running configuration. But I do not get any interface information, or any sub interface information including port channel in this.
Any suggestions.
This

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 10:11 AM
filter = """
<filter>
<include xmlns="urn:ietf:params:xml:ns:yang:Cisco-IOS-XE-cfg">
<interfaces/>
</include>
</filter>
"""
running_config = m.get_config("running", filter=filter).xml
print(xml.dom.minidom.parseString(running_config).toprettyxml())
Connect with me https://bigevilbeard.github.io
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 12:24 PM
strange, but this code was working earlier.
According to the netconf-yang protocol it should have returned the complete configuration. Anyways I tried your suggestions and still not getting anything.
import xmltodict
import xml.dom.minidom
from ncclient import manager
router = {
'ip': '192.1168.100.221',
'port': '830',
'username': 'admin',
'password': 'XXXXXXXXXXXX'
}
netconf_filter = """
<filter>
<include xmlns="urn:ietf:params:xml:ns:yang:Cisco-IOS-XE-cfg">
<interfaces/>
</include>
</filter>
"""
m = manager.connect(host=router['ip'], port=router['port'], username=router['username'],
password=router['password'],device_params={'name':'iosxe'} ,hostkey_verify=False)
running_config = m.get(filter=netconf_filter).xml
print(xml.dom.minidom.parseString(running_config).toprettyxml())
m.close_session()
gives me:
$ python3 newfile2.py
Traceback (most recent call last):
File "newfile2.py", line 25, in <module>
running_config = m.get(filter=netconf_filter).xml
....
raise self._reply.error
ncclient.operations.rpc.RPCError: {'type': 'protocol', 'tag': 'unknown-element', 'app_tag': None, 'severity': 'error', 'info': '<?xml version="1.0" encoding="UTF-8"?><error-info xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><bad-element>filter</bad-element>\n</error-info>\n', 'path': '\n /rpc/get\n ', 'message': None}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 01:47 PM
Try it uses the itef model though
from ncclient import manager
import os
import json
# Set up device info
username=os.environ["CSR1_USER"]
password=os.environ["CSR1_PASSWORD"]
port=os.environ["CSR1_PORT_NETCONF"]
host=os.environ["CSR1_HOST"]
device_params={"name":"iosxe"}
netconf_filter = """ <filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"></interfaces> </filter> """
with manager.connect(host=host, port=port, username=username, password=password, hostkey_verify=False, device_params=device_params) as m:
c = m.get_config('running', netconf_filter).data_xml
with open("%s_int.xml" % host, 'w') as f:
f.write(c)
Connect with me https://bigevilbeard.github.io
