<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Passing variable values to Device Template or Service Instance in NSO Developer Hub Discussions</title>
    <link>https://community.cisco.com/t5/nso-developer-hub-discussions/passing-variable-values-to-device-template-or-service-instance/m-p/4521848#M6735</link>
    <description>&lt;P&gt;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.&lt;BR /&gt;&lt;BR /&gt;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?&lt;/P&gt;
&lt;PRE&gt;devices apply-template template-name NCA variable { name var-aaa-server value 'xyz' }&lt;/PRE&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Dec 2021 23:12:02 GMT</pubDate>
    <dc:creator>jjagrit</dc:creator>
    <dc:date>2021-12-20T23:12:02Z</dc:date>
    <item>
      <title>Passing variable values to Device Template or Service Instance</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/passing-variable-values-to-device-template-or-service-instance/m-p/4521848#M6735</link>
      <description>&lt;P&gt;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.&lt;BR /&gt;&lt;BR /&gt;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?&lt;/P&gt;
&lt;PRE&gt;devices apply-template template-name NCA variable { name var-aaa-server value 'xyz' }&lt;/PRE&gt;
&lt;P class="p1"&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 23:12:02 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/passing-variable-values-to-device-template-or-service-instance/m-p/4521848#M6735</guid>
      <dc:creator>jjagrit</dc:creator>
      <dc:date>2021-12-20T23:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Passing variable values to Device Template or Service Instance</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/passing-variable-values-to-device-template-or-service-instance/m-p/4527663#M6746</link>
      <description>&lt;P&gt;I do this via an RESTCONF API call.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: Make sure your variables key "value" has the single quotes inside the double quotes or the call will fail.&lt;/P&gt;&lt;P&gt;Python example, you could add logic to loop over values if desired.&lt;/P&gt;&lt;PRE&gt;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': '&amp;lt;password&amp;gt;'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)&lt;/PRE&gt;&lt;P&gt;Otherwise, I have not used it but you can probably use the ncs_cmd cli command to push from a file of commands.&lt;/P&gt;&lt;PRE&gt;nsodev@ncslab:~$ ncs_cmd -h
Usage:
  ncs_cmd [options] [filename]
  ncs_cmd [options] -c &amp;lt;script&amp;gt;
  ncs_cmd -h | -h commands | -h &amp;lt;command-name&amp;gt;
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 &amp;lt;address&amp;gt;   Connect to NCS at &amp;lt;address&amp;gt; (default 127.0.0.1)
  -p &amp;lt;port&amp;gt;      Connect to NCS at &amp;lt;port&amp;gt; (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 &amp;lt;user&amp;gt;      Connect to maapi as &amp;lt;user&amp;gt; (default system)
  -g &amp;lt;group&amp;gt;     Connect to maapi with group &amp;lt;group&amp;gt; (more than one allowed)
  -x &amp;lt;ctxt&amp;gt;      Connect to maapi with context &amp;lt;ctxt&amp;gt; (default system)
  -s             Perform each command in a different session
  -c &amp;lt;string&amp;gt;    Commands are read from &amp;lt;string&amp;gt; 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 &amp;lt;cmd-name&amp;gt;  Show help for &amp;lt;cmd-name&amp;gt; and exit
  -h commands    List all available commands and exit&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jan 2022 21:55:51 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/passing-variable-values-to-device-template-or-service-instance/m-p/4527663#M6746</guid>
      <dc:creator>tsiemers1</dc:creator>
      <dc:date>2022-01-06T21:55:51Z</dc:date>
    </item>
  </channel>
</rss>

