cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
706
Views
5
Helpful
1
Replies

Passing variable values to Device Template or Service Instance

jjagrit
Cisco Employee
Cisco Employee

Hi NSO Community, I am new to NSO and I wanted to know if we can pass values to the variables present in the device template via some file or logic instead of passing them while applying the template.

For example, Let's suppose I have a template named NCA that accepts variable var-aaa-server, so instead of passing its value like shown below, Is it possible to read it from some file?

devices apply-template template-name NCA variable { name var-aaa-server value 'xyz' }

 

1 Reply 1

tsiemers1
Spotlight
Spotlight

I do this via an RESTCONF API call. 

Note: Make sure your variables key "value" has the single quotes inside the double quotes or the call will fail.

Python example, you could add logic to loop over values if desired.

import requests
import json

url = "https://ncslab.local/restconf/data/tailf-ncs:devices/device=xeLabDevice01/apply-template"

payload = json.dumps({
  "template-name": "apiTemplateExample",
  "variable": {
    "name": "description",
    "value": "'api changed'"
  }
})
headers = {
  'Content-Type': 'application/yang-data+json',
  'Authorization': '<password>'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Otherwise, I have not used it but you can probably use the ncs_cmd cli command to push from a file of commands.

nsodev@ncslab:~$ ncs_cmd -h
Usage:
  ncs_cmd [options] [filename]
  ncs_cmd [options] -c <script>
  ncs_cmd -h | -h commands | -h <command-name>
A utility that provides a command line interface towards some cdb
and maapi functions. Commands are expected in filename (or stdin
if not provided). Commands can also be given using the -c option.
Valid options are:
  -d             Increase debug level for each -d flag
  -a <address>   Connect to NCS at <address> (default 127.0.0.1)
  -p <port>      Connect to NCS at <port> (default 4565)
  -r             Commands work on 'running' database
  -S             Commands work on 'startup' database
  -o             CDB commands work on CDB operational database
  -e             MAAPI commands work on candidate database
  -I             MAAPI commands work on 'intended' database
  -f [w][p][r|s] Use cdb_start_session2() to start the CDB session - values
                 w/p/r/s set the CDB_LOCK_WAIT/PARTIAL/REQUEST/SESSION flags
  -F [d]         Use maapi_start_trans_flags() to start the transaction.
                 Value d sets the MAAPI_FLAG_DELAYED_WHEN flag.
  -u <user>      Connect to maapi as <user> (default system)
  -g <group>     Connect to maapi with group <group> (more than one allowed)
  -x <ctxt>      Connect to maapi with context <ctxt> (default system)
  -s             Perform each command in a different session
  -c <string>    Commands are read from <string> instead of a file
  -m             Don't call confd_load_schemas()
  -U             Make all output unbuffered
  -L             diff_iterate on leaf-lists as leaf, not list [deprecated]
  -h             Display this text and exit
  -h <cmd-name>  Show help for <cmd-name> and exit
  -h commands    List all available commands and exit