Showing results for 
Search instead for 
Do you mean 
cancel
7781
Views
14
Helpful
16
Comments

Create a device using REST

by Cisco Employee ‎06-26-2017 09:56 AM - edited ‎03-01-2019 04:20 AM

Create the Device

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

Fetch SSH Keys

curl -H "Content-Type:application/vnd.yang.data+xml" -X POST -u admin:admin http://localhost:8080/api/running/devices/device/ios3/ssh/_operations/fetch-host-keys

Sync From

curl -H "Content-Type:application/vnd.yang.data+xml" -X POST -u admin:admin http://localhost:8080/api/running/devices/device/ios3/_operations/sync-from

ios3.xml

<device xmlns="http://tail-f.com/ns/ncs">
  <name>ios3</name>
  <address>127.0.0.1</address>
  <port>10022</port>
  <state>
    <admin-state>unlocked</admin-state>
  </state>
  <authgroup>default</authgroup>
  <device-type>
    <cli>
   <ned-id xmlns:ios-id="urn:ios-id">ios-id:cisco-ios</ned-id>
    </cli>
  </device-type>
</device
>

Comments
by Cisco Employee
on ‎08-24-2017 01:57 PM
by Level 1
on ‎09-05-2017 02:56 PM

Outstanding!

  Thank you so much!!

by Cisco Employee
on ‎01-04-2018 04:43 PM

A little bit late on this thread but I have issue using the processes described above for an IOS-XR devices

I am using NSO 4.5.1 with the latest ios-xr package installed

cisco@ncs# show packages package package-version

          PACKAGE

NAME VERSION

----------------------

cisco-iosxr 6.3.2

cisco-pnp 1.10.0

pioneer 2.24.0

spine1 1.0

curl -H "Content-Type:application/vnd.yang.data+xml" -X PUT -u admin:admin -d @ios-xr1.xml http://localhost:8080/api/running/devices/device/ios-xr1

ios-xr1.xml

----------------

<device xmlns="http://tail-f.com/ns/ncs">

  <name>ios-xr1</name>

  <address>172.30.13.8</address>

  <port>22</port>

  <state>

    <admin-state>unlocked</admin-state>

  </state>

  <authgroup>dev-FOC21074JRT</authgroup>

  <device-type>

  <cli>

   <ned-id xmlns:ios-id="urn:ios-id">ios-id:cisco-ios-xr</ned-id>

    </cli>

  </device-type>

</device>

Error

------

cisco@nso-server:~/NSO/rest$ ./create-dev.sh

<errors xmlns="http://tail-f.com/ns/tailf-rest-error">

  <error>

    <error-tag>malformed-message</error-tag>

    <error-urlpath>/api/running/devices/device/ios-xr1</error-urlpath>

    <error-message>invalid value for: ned-id in /ncs:devices/ncs:device[ncs:name='ios-xr1']/ncs:device-type/ncs:cli/ncs:ned-id: "ios-id:cisco-ios-xr" is not a valid value.</error-message>

  </error>

</errors>

Same error is I change the ned-id from cisco-ios-xr to cisco-ios

creating the device with the ned-id cisco-ios-xr by hand works perfectly

by Cisco Employee
on ‎01-04-2018 06:21 PM

Easiest to get I right is using the CLI and an existing device:

Show device device foo device-type | display xml

That should give you something to cut and paste.

//F

Sent from my iPhone

by Cisco Employee
on ‎01-05-2018 12:03 AM

Agree with Fredrik,

With a new NED, ned-id should be:

admin> show configuration devices device pe1 device-type  | display xml

<config xmlns="http://tail-f.com/ns/config/1.0">

  <devices xmlns="http://tail-f.com/ns/ncs">

  <device>

    <name>pe1</name>

      <device-type>

        <cli>

          <ned-id xmlns:cisco-ios-xr-id="http://tail-f.com/ned/cisco-ios-xr-id">cisco-ios-xr-id:cisco-ios-xr</ned-id>

        </cli>

      </device-type>

  </device>

  </devices>

</config>

[ok][2018-01-05 09:02:40]

admin>

Roque

by Cisco Employee
on ‎01-05-2018 11:24 AM

Thank you guys I did not know you could output the command in XML, it works now ! For future reference here is the correct XML file for my example

<device xmlns="http://tail-f.com/ns/ncs">

  <name>ios-xr1</name>

  <address>172.30.13.8</address>

  <port>22</port>

  <state>

    <admin-state>unlocked</admin-state>

   </state>

   <authgroup>dev-FOC21074JRT</authgroup>

   <device-type>

     <cli>

       <ned-id xmlns:cisco-ios-xr-id="http://tail-f.com/ned/cisco-ios-xr-id">cisco-ios-xr-id:cisco-ios-xr</ned-id>  

     </cli>  

   </device-type>

</device>

by Cisco Employee
on ‎02-05-2018 01:00 PM

Trying to do the same thing with JSON instead but getting 400/405 errors:

{"errors": {"error": [{"error-message": "post to a nonexistent list resource", "error-urlpath": "/api/config/devices/device/ucsm011/config/ucs:org/service-profile/test", "error-tag": "malformed-message"}]}}

curl -X POST -u nsouser:nsouser -H "Content-Type: application/vnd.yang.data+json" http://127.0.0.1:8080/api/config/devices/device/ucsm011/config/org/service-profile -d @innopodtest.json

{"errors": {"error": [{"error-message": "POST on list must be on list element", "error-urlpath": "/api/config/devices/device/ucsm011/config/ucs:org/service-profile", "error-tag": "malformed-message"}]}}

Not sure which is the correct path here nor the correct data schema.  Pulled the config with the following:


curl -s -X GET -u nsouser:nsouser -H "Accept: application/vnd.yang.data+json" "http://127.0.0.1:8080/api/config/devices/device/ucsm011/config/org/?deep" > ucsm011.yaml 2>&1

and here are the first few lines followed by the snipped i am trying to use to configure.

[start...]

{

   "tailf-ned-cisco-ucs:org": {

     "service-profile": [

       {

[...end]

{

    "boot-policy": "pxe",

    "identity": {

        "dynamic-uuid": "00000000-0000-0000-1111-111111111110"

    },

    "local-disk-policy": "disk-policy",

    "name": "nsotest",

    "vcon-assign": {

        "ethernet": {

            "fc2": [

                {

                    "admin-vcon": "any",

                    "host-port": "any",

                    "order": 1,

                    "vnic-vhba": "eth0"

                }

            ]

        }

    },

    "vnic": [

        {

            "eth-if": [

                {

                    "name": "default"

                },

                {

                    "default-net": "yes",

                    "name": "somevlan"

                }

            ],

            "identity": {

                "dynamic-mac": "00:25:B5:E9:12:00"

            },

            "name": "eth0",

            "order": 1

        },

    ],

}

by Cisco Employee
on ‎02-05-2018 02:24 PM

Any difference if you use PUT?

I tried this with the IOS NED:

curl -u admin:admin -X PUT -H "Content-Type: application/vnd.yang.data+json" -d @arp.json http://localhost:8080/api/running/devices/device/volvo-fw-router-CSR1kv-CSR-esc0-1/config/ios:ip/gratuitous-arps-conf

arp.json:

{

  "tailf-ned-cisco-ios:gratuitous-arps-conf": {

    "gratuitous-arps": true

  }

}

by Cisco Employee
on ‎02-05-2018 02:29 PM

Sorry, I mean to mention I tried PUT as well. 

SECHANDL-M-41AW:NSO sechandl$ curl -X PUT -u nsouser:nsouser -H "Content-Type: application/vnd.yang.data+json" http://127.0.0.1:8080/api/config/devices/device/ucsm011/config/ucs:org/service-profile/nsotest -d @innopodtest.json

{"errors": {"error": [{"error-message": "syntax error", "error-urlpath": "/api/config/devices/device/ucsm011/config/ucs:org/service-profile/nsotest", "error-tag": "malformed-message"}]}}

SECHANDL-M-41AW:NSO sechandl$ curl -X PUT -u nsouser:nsouser -H "Content-Type: application/vnd.yang.data+json" http://127.0.0.1:8080/api/config/devices/device/ucsm011/config/ucs:org/service-profile -d @innopodtest.json

SECHANDL-M-41AW:NSO sechandl$ curl -X PUT -u nsouser:nsouser -H "Content-Type: application/vnd.yang.data+json" http://127.0.0.1:8080/api/config/devices/device/ucsm011/config/ucs:org -d @innopodtest.json

{"errors": {"error": [{"error-message": "syntax error", "error-urlpath": "/api/config/devices/device/ucsm011/config/ucs:org", "error-tag": "malformed-message"}]}}

The service-profile element in UCS org is a list.  Not sure if different semantics exist for lists?

-s

by Cisco Employee
on ‎02-05-2018 02:38 PM

A bit, you PUT/POST to base-url/<key>, another example:

http://localhost:8080/api/running/nfvo/ns-info/esc/ns-info/MyNSInfo

{

  "tailf-etsi-rel2-nfvo-esc:ns-info": {

    "id": "MyNSInfo",

    "tenant": "volvo",

...

}

by Cisco Employee
on ‎02-05-2018 04:06 PM

Errors about non-existent list resource as well which seems like a clue.

SECHANDL-M-41AW:NSO sechandl$ curl -X POST -u nsouser:nsouser -H "Content-Type: application/vnd.yang.data+json" http://127.0.0.1:8080/api/config/devices/device/ucsm011/config/org/service-profile -d @innopodtest.json

{"errors": {"error": [{"error-message": "POST on list must be on list element", "error-urlpath": "/api/config/devices/device/ucsm011/config/ucs:org/service-profile", "error-tag": "malformed-message"}]}}

SECHANDL-M-41AW:NSO sechandl$ curl -X POST -u nsouser:nsouser -H "Content-Type: application/vnd.yang.data+json" http://127.0.0.1:8080/api/config/devices/device/ucsm011/config/org/service-profile/nsotest -d @innopodtest.json

{"errors": {"error": [{"error-message": "post to a nonexistent list resource", "error-urlpath": "/api/config/devices/device/ucsm011/config/ucs:org/service-profile/nsotest", "error-tag": "malformed-message"}]}}

SECHANDL-M-41AW:NSO sechandl$ curl -X PUT -u nsouser:nsouser -H "Content-Type: application/vnd.yang.data+json" http://127.0.0.1:8080/api/config/devices/device/ucsm011/config/org/service-profile/nsotest -d @innopodtest.json

{"errors": {"error": [{"error-message": "syntax error", "error-urlpath": "/api/config/devices/device/ucsm011/config/ucs:org/service-profile/nsotest", "error-tag": "malformed-message"}]}}

{

    "boot-policy": "pxe",

    "identity": {

        "dynamic-uuid": "00000000-0000-0000-1111-111111111110"

    },

    "local-disk-policy": "disk-policy",

    "name": "nsotest",

    "vcon-assign": {

        "ethernet": {

            "fc2": [

                {

                    "admin-vcon": "any",

                    "host-port": "any",

                    "order": 1,

                    "vnic-vhba": "eth0"

                }

            ]

        }

    },

    "vnic": [

        {

            "eth-if": [

                {

                    "name": "default"

                },

                {

                    "default-net": "yes",

                    "name": "somevlan"

                }

            ],

            "identity": {

                "dynamic-mac": "00:25:B5:E9:12:00"

            },

            "name": "eth0",

            "order": 1

        },

    ],

}

by Cisco Employee
on ‎02-05-2018 04:08 PM

I think I see it, you have the wrong URL, should be /api/running/..., you have /api/config/...

by Cisco Employee
on ‎02-05-2018 05:24 PM

Thanks!

After the URL fix I just had to fiddle with the content of the JSON and now it is working with the following:

 

curl -X PUT -u nsouser:nsouser -H "Content-Type: application/vnd.yang.data+json" http://127.0.0.1:8080/api/running/devices/device/ucsm011/config/ucs:org/service-profile/nsotest -d @innopodtest.json

{ "service-profile": [

    {

    "boot-policy": "pxe",

    "identity": {

        "dynamic-uuid": "00000000-0000-0000-1111-111111111110"

    },

    "local-disk-policy": "disk-policy",

    "name": "nsotest",

    "vcon-assign": {

        "ethernet": {

            "fc2": [

                {

                    "admin-vcon": "any",

                    "host-port": "any",

                    "order": 1,

                    "vnic-vhba": "eth0"

                }

            ]

        }

    },

    "vnic": [

        {

            "eth-if": [

                {

                    "name": "default"

                },

                {

                    "default-net": "yes",

                    "name": "somevlan"

                }

            ],

            "identity": {

                "dynamic-mac": "00:25:B5:E9:12:00"

            },

            "name": "eth0",

            "order": 1

        }

    ]

    }]}

by Cisco Employee
on ‎02-05-2018 05:30 PM

Awesome!!

by Level 1
‎09-26-2019 03:32 AM - edited ‎09-26-2019 04:56 AM

what if i want to add device to specific group, i tried to do it like below using python:

#add device to group
resp = requests.post("http://localhost:8080/api/running/devices/device-group/xr-test/device-name/xr1" , auth=auth, headers=headers)
print(resp)

 

put it response with 404.

any idea about how to add multiple devices to a group ?

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community:

Quick Links
Polls
AI-powered tools for network troubleshooting are likely to be part of everyone’s workflow sooner or later. What is the single biggest challenge or concern you see with adopting these tools in your organization?