06-19-2023 08:06 AM
Hi,
I am trying to use the operations data to query for the dhcp lease information.
Below is the snippet of netconf-yang and the code.
filter = """
<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-dhcp-oper">
<dhcp-oper-data>
<dhcpv4-server-oper>
</dhcpv4-server-oper>
</dhcp-oper-data>
</native>
</filter>
"""
# Establish a NETCONF session with the device
with manager.connect(host="X.X.X.X", port=XXX, username="XXX", password="XXXXXXXX", hostkey_verify=False, device_params={'name':'csr'}) as m:
# Retrieve the DHCP pool configuration
response = m.get("running", filter)
# Print the XML response
dom = xml.dom.minidom.parseString(response.xml)
pretty_xml_as_string = dom.toprettyxml()
print(pretty_xml_as_string)
This returns error as below
[knanda@stratos-rochester-directlink-vsi code]$ python dhcp_stats.py
Traceback (most recent call last):
File "X/code/dhcp_stats.py", line 82, in <module>
response = m.get("running", filter)
File "X/.local/lib/python3.9/site-packages/ncclient/manager.py", line 246, in execute
return cls(self._session,
File "X/.local/lib/python3.9/site-packages/ncclient/operations/retrieve.py", line 83, in request
node.append(util.build_filter(filter))
File "X/.local/lib/python3.9/site-packages/ncclient/operations/util.py", line 74, in build_filter
rep = validated_element(spec, ("filter", qualify("filter"),
File "X/.local/lib/python3.9/site-packages/ncclient/xml_.py", line 150, in validated_element
ele = to_ele(x)
File "X/.local/lib/python3.9/site-packages/ncclient/xml_.py", line 129, in to_ele
return x if etree.iselement(x) else etree.fromstring(x.encode('UTF-8'), parser=_get_parser(huge_tree))
File "src/lxml/etree.pyx", line 3257, in lxml.etree.fromstring
File "src/lxml/parser.pxi", line 1916, in lxml.etree._parseMemoryDocument
File "src/lxml/parser.pxi", line 1803, in lxml.etree._parseDoc
File "src/lxml/parser.pxi", line 1144, in lxml.etree._BaseParser._parseDoc
File "src/lxml/parser.pxi", line 618, in lxml.etree._ParserContext._handleParseResultDoc
File "src/lxml/parser.pxi", line 728, in lxml.etree._handleParseResult
File "src/lxml/parser.pxi", line 657, in lxml.etree._raiseParseError
File "<string>", line 1
lxml.etree.XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1
06-19-2023 10:28 AM
hi @kn2022
Verify that the YANG model for the DHCP operational data is supported by your device's software version. Some YANG models may not be available or supported on certain device versions, and attempting to retrieve data that is not supported can result in parsing errors.
06-19-2023 07:28 PM
Thanks. I think it does support it. I checked on capabilities and I find these two being listed.
**************************************************
http://cisco.com/ns/yang/Cisco-IOS-XE-dhcp?module=Cisco-IOS-XE-dhcp&revision=2020-07-04
**************************************************
http://cisco.com/ns/yang/Cisco-IOS-XE-dhcp-oper?module=Cisco-IOS-XE-dhcp-oper&revision=2019-05-01
**************************************************
when I run the following code
# Establish a NETCONF session with the device
with manager.connect(**device) as m:
for capability in m.server_capabilities:
print('*'* 50)
print(capability)
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