I'm trying to use Netconf on Cisco IOS XE Router This one Here it's Public but Whenever I use a filter on my commands of get_config
, edit_config
or get I get an error. This is is on Cisco iox XE version 17.3.
The get_config
command does work if no filter is applied output shown here.
I have tried this on 16.9.3 on cisco ios xe and the I used the same code and it didn't give me errors. Have I just misunderstood how pyang or xml works?
What I can do Right now is connect to the router and get the config without a filter but When I try a filter I get this error:
ncclient.operations.rpc.RPCError: {'type': 'protocol', 'tag': 'unknown-element', 'app_tag': None, 'severity': 'error', 'info': 'filter\n\n', 'path': '\n /rpc/get-config\n ', 'message': None}
What my code looks like for get_config
router = manager.connect(
host="sandbox-iosxe-latest-1.cisco.com",
port=830,
username="admin",
password="C1sco12345",
hostkey_verify=False
)
filter2 = """
<filter>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" />
</filter>
"""
netconf = router.get_config(source="running", filter=filter2)
For edit_config
I'm just doing hostname to keep it simple. Here is the code:
netconfnewhostname = """
<config>
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
<hostname>DangledwasHere</hostname>
</native>
</config>
"""
netconf_reply = router.edit_config(netconfnewhostname, target="running")
print(xml.dom.minidom.parseString(netconf_reply.xml).toprettyxml())
And Finally for get
command:
netconf_filterinterface = """
<filter>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"/>
</filter>
"""
netconfinterfaces = router.get(filter=netconf_filterinterface)
I suspect you should specify namespace as for
<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">