cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
830
Views
10
Helpful
2
Replies

XPATH error trying to access Loopback interface

RichardD2
Level 1
Level 1

Can someone explain the correct way to format the following yang:

augment /ncs:services {


  list site_leaf_rd-set {
    key name;

    uses ncs:service-data;
    ncs:servicepoint "site_leaf_rd-set";

    leaf device {
      tailf:info "Device name";
        type leafref {
          path "/ncs:devices/ncs:device/ncs:name";
        }
    }

    leaf name {
      type string;
    }

      list set {
        key value;

        leaf value {
          type leafref {
            path "/devices/device[name=current()/../../name]/config/cisco-ios-xr:interface/Loopback[id='0']/ipv4/address/ip";
          }
        }
  }
 }
}
}

Gives me this error:

yang/site_leaf_rd-set.yang:51: error: bad argument value "/devices/device[name=current()/../../name]/config/cisco-ios-xr:interface/Loopback[id='0']/ipv4/address/ip", should be of type path-arg
Makefile:26: recipe for target '../load-dir/site_leaf_rd-set.fxs' failed
make: *** [../load-dir/site_leaf_rd-set.fxs] Error 1

I have a netsim running with the configuration I am modeling:

show full-configuration devices device router_0 config interface Loopback 0 | display xpath
/devices/device[name='router_0']/config/cisco-ios-xr:interface/Loopback[id='0']/ipv4/address/ip 1.2.3.4
/devices/device[name='router_0']/config/cisco-ios-xr:interface/Loopback[id='0']/ipv4/address/mask 255.255.255.255
/devices/device[name='router_0']/config/cisco-ios-xr:interface/Loopback[id='0']/ipv6/address/prefix-list[prefix='masked']
/devices/device[name='router_0']/config/cisco-ios-xr:interface/Loopback[id='0']/ipv6/enable
/devices/device[name='router_0']/config/cisco-ios-xr:interface/Loopback[id='0']/shutdown

Also tested using:
ncs_cmd -c "xe /devices/device[name='router_0']/config/interface/Loopback[id='0']/ipv4/address/ip"
XPATH_TRACE: exists(/devices/device[name='router_0']) = true

XPATH_TRACE: exists(/devices/device[name='router_0']/config/cisco-ios-xr:interface/Loopback[id='0']) = true

XPATH_TRACE: get_elem(/devices/device[name='router_0']/config/cisco-ios-xr:interface/Loopback[id='0']/ipv4/address/ip) = 1.2.3.4

Is the issue with how I am addressing 'current'? I feel like I have tried every combination here. Any help would be much appreciate

@Larry Manor

@Dan.Sullivan 

2 Replies 2

tcragg1
Cisco Employee
Cisco Employee

Since you have a leafref pointing to the device as part of the model, it might be simpler to have the value leaf use that with a deref() statement rather than having a separate name leaf (which I presume is just going to be populated with the same value you select in the device leaf). I don't have an IOS-XR device to hand to test with, but I think the leafref path for the value leaf would look something like this:

 

path "deref(../../device)/../ncs:config/cisco-ios-xr:interface/cisco-ios-xr:Loopback/cisco-ios-xr:ipv4/cisco-ios-xr:address/cisco-ios-xr:ip";

 

In terms of restricting it to a single interface, I am not sure if that is possible directly through the path (I run into similar path-args errors to the ones you saw when I try something similar). You might be able to use a must constraint within the value leaf to enforce that the id of the Loopback is 0 instead, which I think would look something like this:

 

must "deref(current())/../../../cisco-ios-xr:id = '0'";

 

The other question I would ask is whether you really need the value leaf in the model? If this is always going to just be the IP address of Loopback 0 for the device, you could perhaps use some python logic in the service template to grab the IP address from the Loopback in CDB instead. That might be simpler than having to use multiple leafrefs in the model.

 

gmuloche
Cisco Employee
Cisco Employee

Not an answer but more an explanation regarding the compilation error about `path-arg`

 

There is a very good explanation on the tail-f forum:

https://discuss.tail-f.com/t/issue-compiling-yang-file-any-help-on-this-model/1218/2

 

essentially here your syntax "Loopback[id='0']" does not comply with the path-arg syntax. the part between bracket should look like [namespace:id=current()/../path-without-predicate] though in your case that would not be very practical.