cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
140
Views
10
Helpful
4
Replies
Highlighted
Cisco Employee

hostname remains same for devices under common list

Hi Team,

 

I am trying to provision multiple devices under common list and I am observing that the value against HOSTNAME is having first device name for all others in the list.

 

Below is the sample yang and template file:

cat yang/HOSTNAME.yang

module HOSTNAME {

  namespace "http://com/example/HOSTNAME";

  prefix HOSTNAME;

 

  import ietf-inet-types {

    prefix inet;

  }

  import tailf-ncs {

    prefix ncs;

  }

 

  list HOSTNAME {

    key NAME;

 

    uses ncs:service-data;

    ncs:servicepoint "HOSTNAME";

 

    leaf NAME {

      type string;

    }

 

    leaf-list DEVICE {

      type leafref {

        path "/ncs:devices/ncs:device/ncs:name";

      }

    }

 

  }

}

 

cat ../templates/HOSTNAME-template.xml

<config-template xmlns="http://tail-f.com/ns/config/1.0" servicepoint="HOSTNAME">

  <devices xmlns="http://tail-f.com/ns/ncs">

    <device><name>{/DEVICE}</name>

      <config>

        <hostname xmlns="http://tail-f.com/ned/cisco-ios-xr">{string(/DEVICE)}</hostname>

      </config>

    </device>

  </devices>

</config-template>

 

Upon using this service and selecting two devices from same list, I see below configs:

SJC-DEV1
hostname SJC-DEV1
PHX-DEV1
hostname SJC-DEV1

 

Please suggest if I am missing anything.

 

Thanks,

Amar

4 REPLIES 4
Cisco Employee

Re: hostname remains same for devices under common list

well...you missing an iterator. Something like this (not tested but check the developer guide):

 

<config-template xmlns="http://tail-f.com/ns/config/1.0" servicepoint="HOSTNAME">

  <devices xmlns="http://tail-f.com/ns/ncs" foreach='{/DEVICE}'>

    <device><name>{.}</name>

      <config>

        <hostname xmlns="http://tail-f.com/ned/cisco-ios-xr">{string(.)}</hostname>

      </config>

    </device>

  </devices>

</config-template>

Cisco Employee

Re: hostname remains same for devices under common list

Thank you @rogaglia . It worked as suggested.

Cisco Employee

Re: hostname remains same for devices under common list

The problem is that the /device in the hostname config is setting back to the first entry in the device leaf-list.

 

When the device leaf-list is hit it will iterate through each of the devices in the list, and set the context to that device.  In this case you want to use device to set the hostname. Since your context is at device, then you'll want to set you hostname to  {.} :

<hostname xmlns="http://tail-f.com/ned/cisco-ios-xr">{.}</hostname>

 

A good way to see what in going on with the template engine processing is to use 'debug template'..

 

admin@ncs% commit dry-run | debug template

Evaluating "/device" (from file "hostname-template.xml", line 5)

Context node: /hostname[name='nh1']

Result:

For /hostname[name='nh1']/device[.='iosxr-0'], it evaluates to "iosxr-0"

For /hostname[name='nh1']/device[.='iosxr-1'], it evaluates to "iosxr-1"

Operation 'merge' on existing node: /devices/device[name='iosxr-0'] (from file "hostname-template.xml", line 5)

Operation 'merge' on existing node: /devices/device[name='iosxr-0']/config/cisco-ios-xr:hostname (from file "hostname-template.xml", line 7)

Evaluating "." (from file "hostname-template.xml", line 7)

Context node: /hostname[name='nh1']/device[.='iosxr-0']

Result:

For /hostname[name='nh1']/device[.='iosxr-0'], it evaluates to "iosxr-0"

Setting /devices/device[name='iosxr-0']/config/cisco-ios-xr:hostname to "iosxr-0"

Operation 'merge' on existing node: /devices/device[name='iosxr-1'] (from file "hostname-template.xml", line 5)

Operation 'merge' on non-existing node: /devices/device[name='iosxr-1']/config/cisco-ios-xr:hostname (from file "hostname-template.xml", line 7)

Evaluating "." (from file "hostname-template.xml", line 7)

Context node: /hostname[name='nh1']/device[.='iosxr-1']

Result:

For /hostname[name='nh1']/device[.='iosxr-1'], it evaluates to "iosxr-1"

Setting /devices/device[name='iosxr-1']/config/cisco-ios-xr:hostname to "iosxr-1"

cli {

    local-node {

        data  devices {

                  device iosxr-0 {

                      config {

             -            cisco-ios-xr:hostname test1;

             +            cisco-ios-xr:hostname iosxr-0;

                      }

                  }

                  device iosxr-1 {

                      config {

             +            cisco-ios-xr:hostname iosxr-1;

                      }

                  }

              }

             +hostname nh1 {

             +    device [ iosxr-0 iosxr-1 ];

             +}

    }

}

 

Cisco Employee

Re: hostname remains same for devices under common list

Thank you @lmanor for your response and suggestion. The "debug template" option would be a help for sure.

I also came across "commit dry-run | debug template and commit | debug xpath and commit | debug service" option to get more info.

 

In my case, I do not have a leaf-list but a container that has list and in this case, I had to use the KEY used under that list to get the current device.

// ---------------- INTERNET_FACING_WAN_ROUTER List --------------------------------
container INTERNET_FACING_WAN_ROUTERS {
tailf:info "Internet facing WAN Device Specific Config";
list INTERNET_FACING_WAN_ROUTER {
key "INTERNET_FACING_WAN_ROUTER";
leaf INTERNET_FACING_WAN_ROUTER {
type leafref {
path "/ncs:devices/ncs:device/ncs:name";
}
}
uses SNMP_SERVER_SPECIFIC_PARAMETERS;
uses TACACS_SPECIFIC_PARAMETERS;
uses SYSLOG_SPECIFIC_PARAMETERS;
uses NTP_SPECIFIC_PARAMETERS;
}
} //container INTERNET_FACING_WAN_ROUTERS