<?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 Loading config using jinja2 templates in NSO Developer Hub Discussions</title>
    <link>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/3520466#M1319</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333px;"&gt;I got into a little discussion about jinja templates the other day and ended up putting together a little example that I thought might be of interest to others. Note that the approach demonstrated here is a little bit fragile, it depends on the way the NSO cli would interpret the template. But, as long as your template is in cisco ios format it should work fairly well.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Also, note that the xml templates are checked against the model at load time, and gives much more robustness than this approach. However especially for experiments in the development phase using templates looking more like dumps from the device can be attractive.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_15192205610641322" jivemacro_uid="_15192205610641322" modifiedtitle="true"&gt;
&lt;P&gt;#!/usr/bin/env python&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;from jinja2 import Environment, FileSystemLoader&lt;/P&gt;
&lt;P&gt;import ncs&lt;/P&gt;
&lt;P&gt;import _ncs.maapi as maapi&lt;/P&gt;
&lt;P&gt;import socket&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Make sure to set /ncs-config/cli/use-expose-ns-prefix to false in ncs.conf&lt;/P&gt;
&lt;P&gt;def loadJinja(device, file, data,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sock=None, th=None, apply_trans=True):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Load and apply jinja2 template&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; env = Environment(loader=FileSystemLoader('.'))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; template = env.get_template(file)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t = template.render(data)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print t &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If no socket is given&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if sock is None:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sock = socket.socket()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maapi.connect(sock, '127.0.0.1', ncs.NCS_PORT)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; trans = None&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Setup a maapi transaction as admin&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if th is None:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maapi.start_user_session(sock, 'admin', 'foo', [],'127.0.0.1',ncs.PROTO_TCP)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; th = maapi.start_trans(sock, ncs.RUNNING, ncs.READ_WRITE)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Load config&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; maapi.load_config_cmds(sock, th, maapi.CONFIG_MERGE | maapi.CONFIG_C_IOS, t, "/devices/device{%s}/config" % (device))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Apply trans&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if apply_trans:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maapi.apply_trans(sock, th, False)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Example usage&lt;/P&gt;
&lt;P&gt;fn = "ios.j2"&lt;/P&gt;
&lt;P&gt;device = "ios0"&lt;/P&gt;
&lt;P&gt;data = { "ip_addr" : "192.168.1.3", "ip_mask" : "255.255.255.0",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "routes" : [ { "network" : "0.0.0.0", "mask" : "0.0.0.0", "gw" : "192.168.1.254"}]}&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;loadJinja(device, fn, data)&lt;/P&gt;
&lt;/PRE&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;ios.j2 is:&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_15192205610599892" jivemacro_uid="_15192205610599892" modifiedtitle="true"&gt;
&lt;P&gt;interface GigabitEthernet0/1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ip address {{ ip_addr }} {{ ip_mask }}&lt;/P&gt;
&lt;P&gt;exit&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;{% for route in routes %}&lt;/P&gt;
&lt;P&gt;ip route {{ route.network }} {{ route.mask }} {{ route.gw }}&lt;/P&gt;
&lt;P&gt;{% endfor %}&lt;/P&gt;
&lt;/PRE&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Also, note that if use-expose-ns-prefix is true, or if there are conflicts between different namespaces you would have to type ios:interface and ios:ip.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 01 Mar 2019 12:06:22 GMT</pubDate>
    <dc:creator>vleijon</dc:creator>
    <dc:date>2019-03-01T12:06:22Z</dc:date>
    <item>
      <title>Loading config using jinja2 templates</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/3520466#M1319</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-size: 13.3333px;"&gt;I got into a little discussion about jinja templates the other day and ended up putting together a little example that I thought might be of interest to others. Note that the approach demonstrated here is a little bit fragile, it depends on the way the NSO cli would interpret the template. But, as long as your template is in cisco ios format it should work fairly well.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Also, note that the xml templates are checked against the model at load time, and gives much more robustness than this approach. However especially for experiments in the development phase using templates looking more like dumps from the device can be attractive.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_15192205610641322" jivemacro_uid="_15192205610641322" modifiedtitle="true"&gt;
&lt;P&gt;#!/usr/bin/env python&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;from jinja2 import Environment, FileSystemLoader&lt;/P&gt;
&lt;P&gt;import ncs&lt;/P&gt;
&lt;P&gt;import _ncs.maapi as maapi&lt;/P&gt;
&lt;P&gt;import socket&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Make sure to set /ncs-config/cli/use-expose-ns-prefix to false in ncs.conf&lt;/P&gt;
&lt;P&gt;def loadJinja(device, file, data,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sock=None, th=None, apply_trans=True):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Load and apply jinja2 template&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; env = Environment(loader=FileSystemLoader('.'))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; template = env.get_template(file)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; t = template.render(data)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print t &lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If no socket is given&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if sock is None:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sock = socket.socket()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maapi.connect(sock, '127.0.0.1', ncs.NCS_PORT)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; trans = None&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Setup a maapi transaction as admin&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if th is None:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maapi.start_user_session(sock, 'admin', 'foo', [],'127.0.0.1',ncs.PROTO_TCP)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; th = maapi.start_trans(sock, ncs.RUNNING, ncs.READ_WRITE)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Load config&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; maapi.load_config_cmds(sock, th, maapi.CONFIG_MERGE | maapi.CONFIG_C_IOS, t, "/devices/device{%s}/config" % (device))&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Apply trans&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if apply_trans:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; maapi.apply_trans(sock, th, False)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Example usage&lt;/P&gt;
&lt;P&gt;fn = "ios.j2"&lt;/P&gt;
&lt;P&gt;device = "ios0"&lt;/P&gt;
&lt;P&gt;data = { "ip_addr" : "192.168.1.3", "ip_mask" : "255.255.255.0",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "routes" : [ { "network" : "0.0.0.0", "mask" : "0.0.0.0", "gw" : "192.168.1.254"}]}&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;loadJinja(device, fn, data)&lt;/P&gt;
&lt;/PRE&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;ios.j2 is:&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_15192205610599892" jivemacro_uid="_15192205610599892" modifiedtitle="true"&gt;
&lt;P&gt;interface GigabitEthernet0/1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ip address {{ ip_addr }} {{ ip_mask }}&lt;/P&gt;
&lt;P&gt;exit&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;{% for route in routes %}&lt;/P&gt;
&lt;P&gt;ip route {{ route.network }} {{ route.mask }} {{ route.gw }}&lt;/P&gt;
&lt;P&gt;{% endfor %}&lt;/P&gt;
&lt;/PRE&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Also, note that if use-expose-ns-prefix is true, or if there are conflicts between different namespaces you would have to type ios:interface and ios:ip.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2019 12:06:22 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/3520466#M1319</guid>
      <dc:creator>vleijon</dc:creator>
      <dc:date>2019-03-01T12:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Loading config using jinja2 templates</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509096#M6706</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/549262"&gt;@vleijon&lt;/a&gt;&amp;nbsp;for this example. it is enlightening!&lt;/P&gt;&lt;P&gt;Would anyone be so kind to comment how the same can be accomplished, if possible using XML?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example,&lt;/P&gt;&lt;PRE&gt;_ncs.maapi.load_config(mgmt.msock, trxn.th, _ncs.maapi.CONFIG_XML, "light.xml")
trxn.apply()&lt;/PRE&gt;&lt;P&gt;where the contents of &lt;STRONG&gt;light.xml&lt;/STRONG&gt; are&lt;/P&gt;&lt;P&gt;(after removing the element &amp;lt;config-template xmlns="&lt;A href="http://tail-f.com/ns/config/1.0" target="_blank" rel="noopener"&gt;http://tail-f.com/ns/config/1.0&lt;/A&gt;"&amp;gt;)&lt;/P&gt;&lt;PRE&gt;  &amp;lt;devices xmlns="http://tail-f.com/ns/ncs"&amp;gt;
   &amp;lt;device&amp;gt;
     &amp;lt;name&amp;gt;nokia-lab03c-ra2&amp;lt;/name&amp;gt;
     &amp;lt;config&amp;gt;
       &amp;lt;configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf"&amp;gt;

        &amp;lt;port&amp;gt;
         &amp;lt;port-id tags="replace"&amp;gt;1/1/c30&amp;lt;/port-id&amp;gt;
         &amp;lt;description tags="replace"&amp;gt;* ip-spotlight * omega * note: proof-of-concept *&amp;lt;/description&amp;gt;
       &amp;lt;/port&amp;gt;

     &amp;lt;/configure&amp;gt;
   &amp;lt;/config&amp;gt;
 &amp;lt;/device&amp;gt;
&amp;lt;/devices&amp;gt;&lt;/PRE&gt;&lt;P&gt;complains about&lt;/P&gt;&lt;PRE&gt;Error: Python cb_action error. external error (19): Error on line 6: no mount id exists for: /ncs:devices/ncs:device[ncs:name='nokia-lab03c-ra2']/ncs:config&lt;/PRE&gt;&lt;P&gt;What I am doing wrong? Will the &lt;STRONG&gt;tags&lt;/STRONG&gt; xml attribute in the .xml file be recognised and acted upon?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PS. ncs_load is recognising the router, the following succeeds&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;$ ncs_load -P "/ncs:devices/ncs:device[ncs:name='nokia-lab03c-ra2']/ncs:config" -Fp&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;with kind regards,&lt;/P&gt;&lt;P&gt;Niko&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 09:26:55 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509096#M6706</guid>
      <dc:creator>nikos_skalis</dc:creator>
      <dc:date>2021-11-29T09:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Loading config using jinja2 templates</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509101#M6707</link>
      <description>That error (no mount id exists for) probably means you are not having a ned id. Either because the device name is completely new or because you are doing replace and not merge. Make sure to use the explicit merge flag in your load.&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Nov 2021 23:14:02 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509101#M6707</guid>
      <dc:creator>vleijon</dc:creator>
      <dc:date>2021-11-26T23:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Loading config using jinja2 templates</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509506#M6708</link>
      <description>&lt;P&gt;Thanks a lot&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/549262"&gt;@vleijon&lt;/a&gt;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;_ncs.maapi.CONFIG_MERGE&lt;/FONT&gt; did the trick &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;There is also&amp;nbsp;&lt;FONT face="courier new,courier"&gt;_ncs.maapi.CONFIG_REPLACE&lt;/FONT&gt;&amp;nbsp;(&lt;A href="https://github.com/NSO-developer/ntool/blob/master/ntool/ntool_modules/ntool_template.py" target="_blank" rel="noopener"&gt;https://github.com/NSO-developer/ntool/blob/master/ntool/ntool_modules/ntool_template.py&lt;/A&gt;) with an inherent "delete" operation I guess, with a purpose which is not clear to me and not working either (same error), which is &lt;U&gt;not&lt;/U&gt; important &lt;STRONG&gt;because&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the flag &lt;FONT face="courier new,courier"&gt;_ncs.maapi.CONFIG_MERGE&lt;/FONT&gt;&amp;nbsp;together with honouring the &lt;FONT face="courier new,courier"&gt;tags&lt;/FONT&gt; xml attribute would be the global &lt;STRONG&gt;solution&lt;/STRONG&gt; supporting all operations (&lt;FONT face="courier new,courier"&gt;replace&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;delete&lt;/FONT&gt;, etc.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;but&lt;/STRONG&gt;, when applying the above .xml document on the router it results in&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;@ncs&amp;gt; show configuration devices device nokia-lab03c-ra2 config conf:configure port 1/1/c30&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;/* Tags: delete */&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;description "* ip-spotlight * omega * note: proof-of-concept *";&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;which means the &lt;FONT face="courier new,courier"&gt;tags&lt;/FONT&gt; xml attribute is not respected, the interface description is still there.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Question&lt;/STRONG&gt;: Is there a way for CiscoNSO to respect the &lt;FONT face="courier new,courier"&gt;tags&lt;/FONT&gt; xml attribute when loading xml-based configuration?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The method&amp;nbsp;&lt;FONT face="courier new,courier"&gt;_ncs.maapi.apply_template&lt;/FONT&gt;&amp;nbsp;respects the &lt;FONT face="courier new,courier"&gt;tags&lt;/FONT&gt; xml attribute. What is the&amp;nbsp;extra call that it makes and honours the &lt;FONT face="courier new,courier"&gt;tags&lt;/FONT&gt; xml attribute?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Nov 2021 09:34:56 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509506#M6708</guid>
      <dc:creator>nikos_skalis</dc:creator>
      <dc:date>2021-11-28T09:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Loading config using jinja2 templates</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509838#M6709</link>
      <description>&lt;P&gt;The "tags" XML attribute is interpreted by NSO/ConfD as tag information that is intended to be used for&amp;nbsp;data organization and filtering purposes.&lt;/P&gt;
&lt;P&gt;You may use the "operation" XML attribute which is interpreted by NSO MAAPI load_config when merging the same way the "operation" attribute is used in a NETCONF &amp;lt;edit-config&amp;gt; operation as described in the NETCONF RFC 6241,&amp;nbsp;&lt;A href="https://datatracker.ietf.org/doc/html/rfc6241#page-38" target="_self"&gt;https://datatracker.ietf.org/doc/html/rfc6241#page-38&lt;/A&gt;&amp;nbsp;and YANG RFC 7950, for example under&amp;nbsp;&lt;A href="https://datatracker.ietf.org/doc/html/rfc7950#section-7.6.7" target="_blank"&gt;https://datatracker.ietf.org/doc/html/rfc7950#section-7.6.7&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I.e. a CONFIG_MERGE with the below "operation" XML attribute will delete the description leaf data.&lt;/P&gt;
&lt;PRE&gt;&amp;lt;description operation="delete"&amp;gt;* ip-spotlight * omega * note: proof-of-concept *&amp;lt;/description&amp;gt;&amp;nbsp;&amp;nbsp;&lt;/PRE&gt;
&lt;P class="p1"&gt;The "operation" attribute is briefly described in the ncs(1) man page for the "--mergexmlfiles" flag, and should be added to the MAAPI load_config documentation too. (Note taken).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 08:35:00 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509838#M6709</guid>
      <dc:creator>cohult</dc:creator>
      <dc:date>2021-11-29T08:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Loading config using jinja2 templates</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509867#M6710</link>
      <description>&lt;P&gt;a&amp;nbsp;w&amp;nbsp;e&amp;nbsp;s&amp;nbsp;o&amp;nbsp;m&amp;nbsp;e&amp;nbsp;! thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 09:25:25 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4509867#M6710</guid>
      <dc:creator>nikos_skalis</dc:creator>
      <dc:date>2021-11-29T09:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Loading config using jinja2 templates</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4524374#M6739</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/549262"&gt;@vleijon&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/523322"&gt;@cohult&lt;/a&gt;&amp;nbsp;for your help so far.&lt;/P&gt;&lt;P&gt;I was exploring the above example around&amp;nbsp;&lt;FONT face="courier new,courier"&gt;_ncs.maapi.load_config_cmds&lt;/FONT&gt; and I am not sure if I understand this correctly. More specifically,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In case of &lt;STRONG&gt;ios&lt;/STRONG&gt;-based operating systems, nso does not accept the above template unless the &lt;FONT face="courier new,courier"&gt;ios:&lt;/FONT&gt; namespace is used. For example, this works&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;                    cmds = """ ios:interface Loopback 12 
                        description "* ip-spotlight * omega * note: proof-of-concept * xxx *" 
                        exit """&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In case of &lt;STRONG&gt;sros&lt;/STRONG&gt;&amp;nbsp;operating systems, nso requires the &lt;FONT face="courier new,courier"&gt;conf:configure&lt;/FONT&gt; part. The following works&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;cmds = """ conf:configure port 1/1/c30 description "* ip-spotlight * omega * note: proof-of-concept *" """&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem with the above approaches is that it misses out additional capabilities present in junos- or sros- based operating systems, that nso supports though.&lt;/P&gt;&lt;P&gt;More specifically, the &lt;FONT face="courier new,courier"&gt;delete&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;insert __ before/after __&lt;/FONT&gt; configuration statements. For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;@ncs% insert devices device nokia-lab03c-ra2 config conf:configure router Base bgp group abc export policy MARKET-X before REJECT-ALL&lt;/PRE&gt;&lt;P&gt;in this case, the &lt;FONT face="courier new,courier"&gt;insert&lt;/FONT&gt; knob is placed before namespace &lt;FONT face="courier new,courier"&gt;conf:configure&lt;/FONT&gt; and the &lt;FONT face="courier new,courier"&gt;before&lt;/FONT&gt; is placed after the namespace &lt;FONT face="courier new,courier"&gt;conf:configure&lt;/FONT&gt;&amp;nbsp;hence &lt;FONT face="courier new,courier"&gt;_ncs.maapi.load_config_cmds&lt;/FONT&gt;&amp;nbsp;doesn't fit the purpose I think.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The native way looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;insert router Base bgp group abc export policy MARKET-X before REJECT-ALL&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Given&lt;/P&gt;&lt;HR /&gt;&lt;OL&gt;&lt;LI&gt;the namespace &lt;FONT face="courier new,courier"&gt;ios:&lt;/FONT&gt; required in case of ios-based operating systems&lt;/LI&gt;&lt;LI&gt;the mixing of native configurations statements between nso and other operating systems (see example with sros and &lt;FONT face="courier new,courier"&gt;insert _ before/after _&lt;/FONT&gt;)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I was wondering&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is there a programmatic way (through any api or library) to issue nso-specific configuration statements (for example,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;insert devices device nokia-lab03c-ra2 config conf:configure router Base bgp group abc export policy MARKET-X before REJECT-ALL&lt;/FONT&gt;) ?&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;with kind regards,&lt;/P&gt;&lt;P&gt;Nikos&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Dec 2021 13:07:06 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4524374#M6739</guid>
      <dc:creator>nikos_skalis</dc:creator>
      <dc:date>2021-12-28T13:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: Loading config using jinja2 templates</title>
      <link>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4527588#M6742</link>
      <description>I think depends a bit on your NSO version actually, it should accept non ios:-prefix in the later versions.&lt;BR /&gt;&lt;BR /&gt;But, you are right with the after/before thing, that will not work.&lt;BR /&gt;&lt;BR /&gt;Luckily, there are other APIs that will work. Easiest is perhaps to use the move option on maagic list: &lt;A href="https://developer.cisco.com/docs/nso/api/#ncs-maagic/ncs.maagic.List" target="_blank"&gt;https://developer.cisco.com/docs/nso/api/#ncs-maagic/ncs.maagic.List&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Jan 2022 19:45:30 GMT</pubDate>
      <guid>https://community.cisco.com/t5/nso-developer-hub-discussions/loading-config-using-jinja2-templates/m-p/4527588#M6742</guid>
      <dc:creator>vleijon</dc:creator>
      <dc:date>2022-01-06T19:45:30Z</dc:date>
    </item>
  </channel>
</rss>

