cancel
Showing results for 
Search instead for 
Did you mean: 
cancel

Create a device using REST

1430
Views
4
Helpful
14
Comments

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
Cisco Employee
Beginner

Outstanding!

  Thank you so much!!

Cisco Employee

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

Cisco Employee

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

Cisco Employee

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

Cisco Employee

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>

Cisco Employee

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

        },

    ],

}

Cisco Employee

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

  }

}

Cisco Employee

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

Cisco Employee

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",

...

}

Cisco Employee

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

        },

    ],

}

Cisco Employee

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

Cisco Employee

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

        }

    ]

    }]}

Cisco Employee

Awesome!!