12-30-2020 03:41 PM
Hello fellows!
I'm working on some tooling with Nornir and making calls via tasks to carry out some automations against NSO RESTCONF API. I'm struggling with getting PATCH method to work though. I've tried a couple different ways, but this example below is in line with the error message of "malformed-message" I'm getting back on any payload. Any tips on what I'm doing wrong here? Probably something simple for those with some experience in this arena.
You may notice that I'm doing a patch on a full device create. I'm just trying to see if I can simplify the process of running tasks from an inventory in Netbox when changes happen. Instead of having a Nornir task that checks for the current configuration, proposed configuration and compares them; just try to patch as is and let NSO return an indicator that the device already exists as-is and will be unchanged.
I will happily provide more information if needed, but like I said before, I'm guessing there's something obvious that I'm missing. Any tips for troubleshooting from the NSO side in logging to solve this would be appreciated also!
PATCH URL:
http://10.0.0.49/restconf/data/tailf-ncs:devices/device=ios
Headers:
'Content-Type: application/yang-patch+xml'
PATCH body:
<yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch"> <patch-id>add-device</patch-id> <edit> <edit-id>add-device-ios</edit-id> <operation>create</operation> <target>/device=ios</target> <value> <device xmlns="http://tail-f.com/ns/ncs" xmlns:ncs="http://tail-f.com/ns/ncs"> <name>ios</name> <address>172.24.0.3</address> <authgroup>default</authgroup> <device-type> <cli> <ned-id xmlns:ios-id="urn:ios-id">ios-id:cisco-ios</ned-id> </cli> </device-type> <state> <admin-state>unlocked</admin-state> </state> </device> </value> </edit> </yang-patch>
Response:
<yang-patch-status xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch"> <patch-id>add-device</patch-id> <edit-status> <edit> <edit-id>add-device-ios</edit-id> <errors> <error> <error-type>application</error-type> <error-tag>malformed-message</error-tag> <error-path xmlns:ncs="http://tail-f.com/ns/ncs">/ncs:devices/ncs:device[ncs:name='ios']</error-path> <error-message></error-message> </error> </errors> </edit> </edit-status> </yang-patch-status>
Solved! Go to Solution.
01-13-2021 03:27 AM
Hello,
this works for me (NSO 5.5 so I changed the NED ID you are using):
URL:
http://{{nso_ip}}:{{nso_port}}/restconf/data/tailf-ncs:devices
Headers:
'Content-Type: application/yang-patch+xml'
'Accept: application/yang-patch+xml'
Payload:
<yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
<patch-id>add-device</patch-id>
<edit>
<edit-id>add-device-ios</edit-id>
<operation>create</operation>
<target>/device=ios</target>
<value>
<device xmlns="http://tail-f.com/ns/ncs">
<name>ios</name>
<address>172.24.0.3</address>
<authgroup>default</authgroup>
<device-type>
<cli>
<ned-id xmlns:cisco-ios-cli-6.67="http://tail-f.com/ns/ned-id/cisco-ios-cli-6.67">cisco-ios-cli-6.67:cisco-ios-cli-6.67</ned-id>
</cli>
</device-type>
<state>
<admin-state>unlocked</admin-state>
</state>
</device>
</value>
</edit>
</yang-patch>
The main difference is in my URL as you will notice is that I don't have the device=ios in the URL.
The reason is that if the target resource - https://tools.ietf.org/html/rfc8072#section-2.1 (not the target data-node described in section 2.4) does not exist then you should get an error according to RFC.
01-13-2021 03:27 AM
Hello,
this works for me (NSO 5.5 so I changed the NED ID you are using):
URL:
http://{{nso_ip}}:{{nso_port}}/restconf/data/tailf-ncs:devices
Headers:
'Content-Type: application/yang-patch+xml'
'Accept: application/yang-patch+xml'
Payload:
<yang-patch xmlns="urn:ietf:params:xml:ns:yang:ietf-yang-patch">
<patch-id>add-device</patch-id>
<edit>
<edit-id>add-device-ios</edit-id>
<operation>create</operation>
<target>/device=ios</target>
<value>
<device xmlns="http://tail-f.com/ns/ncs">
<name>ios</name>
<address>172.24.0.3</address>
<authgroup>default</authgroup>
<device-type>
<cli>
<ned-id xmlns:cisco-ios-cli-6.67="http://tail-f.com/ns/ned-id/cisco-ios-cli-6.67">cisco-ios-cli-6.67:cisco-ios-cli-6.67</ned-id>
</cli>
</device-type>
<state>
<admin-state>unlocked</admin-state>
</state>
</device>
</value>
</edit>
</yang-patch>
The main difference is in my URL as you will notice is that I don't have the device=ios in the URL.
The reason is that if the target resource - https://tools.ietf.org/html/rfc8072#section-2.1 (not the target data-node described in section 2.4) does not exist then you should get an error according to RFC.
01-13-2021 05:42 AM
Cool thanks. I see the error of my ways!
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