cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3772
Views
1
Helpful
12
Replies

NSO DEVICE ADD via REST API

allenvose
Level 1
Level 1

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;

        }

    }

12 Replies 12

frjansso
Cisco Employee
Cisco Employee

Yes, please see Create a device using REST.

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

Can you try adding @ before the filename for -d option?

-d @testxr.xml

Without @, you are sending the string "testxr.xml"

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.

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.

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?

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.

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!!

Glad to help!

This does not work anymore

Use this instead: 

https://community.cisco.com/t5/nso-developer-hub-documents/create-a-device-using-rest/tac-p/3635277/highlight/true#M16

 

Then NED ID syntax in the XML file changes see the post linked above

The closing tag for <device> is missing the slash, </device>.

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>