08-21-2017 11:21 AM - edited 03-01-2019 03:58 AM
Is there a way to load a device directly into NSO via REST API?
For example, a device can be loaded via configuration CLI, such as following example, however is there a way to do so via REST API?
devices {
device TEXAS {
address 1.1.1.1;
port 22;
authgroup NSOAUTH;
device-type {
netconf;
}
state {
admin-state unlocked;
}
}
08-21-2017 11:26 AM
Yes, please see Create a device using REST.
08-21-2017 01:00 PM
I used CURL as follows:
curl -H "Content-Type:application/vnd.yang.data+xml" -X PUT -u admin:admin -d testxr.xml http://x.x.x.x:8080/api/running/devices/device/testxr
testxr.xml
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>testxr</name>
<address>x.x.x.x</address>
<state>
<admin-state>unlocked</admin-state>
</state>
<authgroup>NSOAUTH</authgroup>
<device-type>
<netconf>
<ned-id xmlns:ned="http://tail-f.com/ns/ncs-ned">ned:netconf</ned-id>
</netconf>
</device-type>
<device>
</devices>
When I run that CURL script, I get the following error:
<errors xmlns="http://tail-f.com/ns/tailf-rest-error">
<error>
<error-tag>malformed-message</error-tag>
<error-urlpath>/api/running/devices/device/testxr</error-urlpath>
<error-message>End-of-file reached in XML stream</error-message>
</error>
</errors>
Can you identify anything that I am doing wrong based upon this output? Also note that I am running NSO version 4.4
08-21-2017 09:30 PM
Can you try adding @ before the filename for -d option?
-d @testxr.xml
Without @, you are sending the string "testxr.xml"
08-22-2017 07:54 AM
I tried it with the @ sign, however the error remains the same.
I note that in your example, the xml file has the "device" hierarchical html tag followed by the "name" hierarchical html tag as listed here:
<device xmlns="http://tail-f.com/ns/ncs">
<name>ios3</name>
Conversely, when I display XML under the device configuration hierarchy for NSO4.4, the structure is different in that the namespace begins with "devices" hierarchical html tag, followed by "device" and then "name" as shown below:
<devices xmlns="http://tail-f.com/ns/ncs">
<device>
<name>testxr</name>
I'm wondering if the XML format that I'm using is incorrect. Do note that I have alternatively started my XML format at the <device> hierarchy, attempting to mirror your format, however it didn't work.
08-22-2017 09:48 AM
Hi!
Yes, I believe you'll need to remove the <devices> tag. The payload shouldn't include the entire "path" to the config, e.g. in your case you shouldn't include "/devices/device/" only "device", if that makes sense.
I'd suggest you download the example for "ios3" and modify that to your needs.
08-22-2017 10:14 AM
I just pulled it down verbatim and loaded it, however I get the same error.
I assume that this is a cut-n-paste from a known working API from your system.
Are you using NSO version 4.4?
08-22-2017 03:36 PM
Yes, 4.4 and I cannot reproduce this, I pasted in the xml from the other post (I've attached it here) and ran:
➜ tmp curl -H "Content-Type:application/vnd.yang.data+xml" -X PUT -u admin:admin -d @ios3.xml http://localhost:8080/api/running/devices/device/ios3
➜ tmp
And it works.
Please download the attached xml and see it makes a difference.
08-23-2017 07:41 AM
Fredrik,
It worked like a charm! Thank you very much!
I was already able to push both device and service templates via the API, however I wasn't able to actually discover the devices via the API. Now that you've helped me out, I can discover the devices, sync configs, etc. This will allow me to build a good, robust web-portal for my customer with NSO as the underpinning muscle!
Thank you VERY much!!
08-23-2017 08:12 AM
Glad to help!
06-10-2019 09:54 PM
This does not work anymore
Use this instead:
Then NED ID syntax in the XML file changes see the post linked above
08-23-2017 01:03 AM
The closing tag for <device> is missing the slash, </device>.
10-01-2018 04:18 PM
Given that to fully add the device to NSO, the ssh key of the device needs to be fetched too, has anyone figured out how to handle that part as well via REST API?
admin@ncs> request devices device R02 ssh fetch-host-keys
the key fetched from above command should fit in XYZ below.
<ssh>
<host-key>
<algorithm>ssh-rsa</algorithm>
<key-data>XYZ</key-data>
</host-key>
</ssh>
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