12-04-2022 09:15 PM
I am trying to write a python script that will revert switchports back to default configuration. I have split the procedure into two separate files.
This file holds the code for the payload and calls the file below - NC_default_interface.py.
This contains the ncclient manager.connect section - NC_connect_to_device.py.
Whenever I run this code, interface G1/0/1 successfully gets reverted back to default configuration. However, on port G1/0/2, I get this error message.
</error-path><error-message xml:lang="en">resource denied: Sync is in progress</error-message><error-info><bad-element>default</bad-element>
</error-info>
I think the session needs to be closed and restarted for each port, but that is just a guess on my part.
I tried m.close and m.session_close(), but those just threw up different error messages.
I have attached the files in question. Thanks in advance.
12-05-2022 12:08 AM - edited 12-05-2022 12:12 AM
Hi
Lock/unlock the datastore for each rpc call. In my case this code is working:
for i in range(1,5):
m.lock(target="running")
rpc_content = f"""
<default xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-rpc">
<interface>GigabitEthernet1/0/{i}</interface>
</default>
"""
result = m.rpc(xml_.to_ele(rpc_content))
print(result.xml)
m.unlock(target="running")
In your case you need something like this:
# snipp
for rpc in payload:
try:
m.lock(target="running")
response = m.dispatch(et.fromstring(rpc))
data = response.xml
m.unlock(target="running")
except RPCError as e:
data = e.xml
pass
# snipp
HTH
Marcel
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