Hi all,
When I connect to a device using
ssh hostname -s netconf, applying the configuration as above in that NETCONF session works without issue.
But when I attempt this using PyEZ as so:
xml = """<rpc>
<load-configuration>
<configuration replace-pattern="testing" with="production">
</configuration>
</load-configuration>
</rpc>"""
cfg.load(xml, format="xml")
I see the following error back in PyEZ:
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: rpc-reply line 1 and load-configuration-results, line 24, column 30
If I set traceoptions on netconf I see the following:
Dec 19 13:43:52 [NETCONF] - [26796] Incoming: <?xml version="1.0" encoding="UTF-8"?><nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:a6e7d990-8192-44cb-8298-e9afeba567da"><load-configuration format="xml" action="replace"><configuration><rpc>
<load-configuration>
<configuration replace-pattern="testing" with="production">
</configuration>
</load-configuration>
</rpc></configuration></load-configuration></nc:rpc>]]>]]>
Dec 19 13:43:52 [NETCONF] - [26796] Outgoing: <nc:rpc-reply xmlns:junos="
http://xml.juniper.net/junos/20.2R0/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:a6e7d990-8192-44cb-8298-e9afeba567da">
Dec 19 13:43:52 [NETCONF] - [26796] Outgoing: <load-configuration-results format="xml" action="update">
Dec 19 13:43:52 [NETCONF] - [26796] Outgoing: <nc:rpc-error>
Dec 19 13:43:52 [NETCONF] - [26796] Outgoing: <nc:error-type>protocol</nc:error-type>
Dec 19 13:43:52 [NETCONF] - [26796] Outgoing: <nc:error-tag>operation-failed</nc:error-tag>
Dec 19 13:43:52 [NETCONF] - [26796] Outgoing: <nc:error-severity>error</nc:error-severity>
Dec 19 13:43:52 [NETCONF] - [26796] Outgoing: <nc:error-message>syntax error, expecting </configuration></nc:error-message>
Dec 19 13:43:52 [NETCONF] - [26796] Outgoing: <nc:error-info>
Dec 19 13:43:52 [NETCONF] - [26796] Outgoing: <nc:bad-element>rpc</nc:bad-element>
...so it looks as though PyEZ is wrapping the XML in <load-configuration> and <configuration> tags already, and I assume this is what's causing the problem, but I can't see how I would get PyEZ to not send those tags/edit its configuration tag accordingly.
Obviously, I could just revert to using ncclient directly instead, but I'd rather not, similarly with using a screen-scraping library or by pull the current configuration's set commands then regex replacing the pattern in python to then create the set commands.
If anyone has any suggestions, that would be great!
Thanks,
Carl