04-10-2022 06:56 AM - edited 04-10-2022 07:23 AM
Hello all, Hope you're doing good.
I'm trying to netconf on my CSR1kv router which I have hosted on my ESXi server.
When I'm trying to debug this code:
from ncclient import manager from devices import router1 netconf_filter = open("filter-ietf-interfaces.xml").read() with manager.connect(host=router1["host"], port=router1["port"], username=router1["username"], password=router1["password"], hostkey_verify=False) as m: interface_netconf = m.get(netconf_filter) print('Getting running config')
I'm getting this error on response:
Exception has occurred: RPCError {'type': 'protocol', 'tag': 'unknown-element', '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} File "C:\Users\aukka\Desktop\DevNetOps\NetConf\ncclient-1.py", line 33, in <module> interface_netconf = m.get(netconf_filter)
Obviously it seems that there's an error with m.get function.
Is there anyone who can help how I can fix this issue?
Thanks,
04-11-2022 05:37 AM
@amiruka06 check this thread on ncclient https://community.cisco.com/t5/application-centric/aci-config-xml-script/td-p/4032990
❯ pip freeze | grep ncc ncclient==0.6.12
This code works
import lxml.etree as et from ncclient import manager from ncclient.operations import RPCError payload = [ ''' <get-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <source> <running/> </source> <filter> <interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces"> <interface> </interface> </interfaces> </filter> </get-config> ''' ] # connect to netconf agent with manager.connect(host="sandbox-iosxe-latest-1.cisco.com", port="830", username="developer", password="C1sco12345", timeout=90, hostkey_verify=False, device_params={'name': 'csr'}) as m: # execute netconf operation for rpc in payload: try: response = m.dispatch(et.fromstring(rpc)) data = response.xml except RPCError as e: data = e._raw print(response.xml)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide