cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
633
Views
0
Helpful
4
Replies

Need help applying template via RESTCONF

I have a very simple template to provide a dayZero configuration to a router.
It works via ncs_cli as : dayZero <name> hostName <newhostname> userName <newUserName> secret <NewSecret>

Using Postman, I'm POSTing to http://{{NSO_IP}}:{{NSO_HTTP_PORT}}/restconf/data/tailf-ncs:devices/device=<device>/apply-template

I'm attempting to send this payload with the POST request but it's failing.
I'm sure it's not correct, but I'm unable to figure out how to organize the variables in the XML syntax correctly.
Can anyone please point me in the right direction?

<input>
<template-name>dayZero</template-name>
<variable>
<name>
<hostName>
<value>"Changme"</value>
</hostname>
<userName>
   <value>"JoeBob"</value>
<userName>
<secret>
   <value>"password123"</value>
</secret>
</name>
</variable>
</input>
4 Replies 4

Ok - Making some progress based on some feedback.

The URL I'm targeting is now: http://{{NSO_IP}}:{{NSO_HTTP_PORT}}/restconf/data/tailf-ncs:services

My payload is now: 

{
"dayZero:dayZero": [
{
"device": "dev-csr",
"hostName": "ChangMe",
"userName": "NewUser",
"secret": "password123"
}
]
}
 
Still getting an error of :
{
"ietf-restconf:errors": {
"error": [
{
"error-type": "application",
"error-tag": "malformed-message",
"error-path": "/tailf-ncs:services",
"error-message": "unknown element: dayZero in /ncs:services/dayZero:dayZero"
}
]
}
}
 
Can anyone point me in the right direction?

Try something like:

 

http://localhost:8080/restconf/data/tailf-ncs:services/dayZero:dayZero
{
  "dayZero": [
    {
      "device": "dev-csr",
...
    }
  ]
}

 

Tip: In the more recent NSO versions, there are lots of RESTCONF examples under examples.ncs/development-guide. Run the *-rc examples (make showcase-rc or demo-rc etc.) that use Python requests to run the RESTCONF variant and print what is sent and received in JSON format.

Hello

Regarding the original question : 
To apply a device template this should be the Body

URL

{{PROTOCOL}}://{{NSO_IP}}:{{NSO_HTTP_PORT}}/restconf/data/tailf-ncs:devices/device={{IOS_XR_DEVICE}}/apply-template/

BODY ( add the remaining variables )

 

<input>
 <template-name>dayZero</template-name>
 <variable>
   <name>HOSTNAME</name>
   <value>'Changeme'</value>
 </variable>
 <variable>
   <name>USERNAME</name>
   <value>'JoeBob'</value>
 </variable>
...
</input>

 

as per last question if you're trying to apply a service be sure you've created the service in the packages folder of your running instance of NSO
ncs-make-package --service-skeleton template dayZero

then you need to do a "packages reload" , edit the YANG model creating the variables ( hostname, username, secret , ... ) and edit the XML with the equivalent device config mapping the YANG variables. 

richsun
Cisco Employee
Cisco Employee

https://gitlab.com/nso-developer/rest-api-explorer should build the POST url and body (in JSON or XML) automatically, by clicking the parameters to be included.