cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1856
Views
15
Helpful
9
Replies

Complex keys in YANG XPath leafref

douglasfir
Level 1
Level 1

Hello,

 

while developing NSO service and using NetConf NED for older versions of IOS XR I am facing a problem with a path to an interface configuration.

 

The problem is that the interface is uniquely defined as "act Loopback3" instead of just "Loobpack3", so I don't know how to define a path in leafref. I have tried just refering to "interface-name" as shown below, but NSO reports an error later.

 

 

        leaf interface_name {
          type leafref {
            path /ncs:devices/ncs:devi:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:interface-name";
          }
        }

Now the question is where and how to put another leaf (ifmgr:active, responsible for "act" part) into the game together with interface-name, since the service is being compiled fine, but when trying to load it into NSO, I get something like the following error:

 

Error: Failed to load ./state/packages-in-use/2/my-service/load-dir/peer-traffic-steering.fxs: Module my-service: The targets of the leafref path for node /services/my-service/interface/interface_name_test differ in type

I tried things like the following, but it doesn't work:

path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr:active ifmgr-cfg:interface-name";   

Thanks a lot!

 

2 Accepted Solutions

Accepted Solutions

Nabsch
Spotlight
Spotlight

Hello,

 

The best way to find the xpath easier is to too use an existing interface then you do a 

show running devices device <yourdevice>config ... | display xpath 

 

 

 

I manage to compile but since i'am not using Netconf on XR device i cannot test if the leafref is working correctly.

 

Can you change your leaf  to this definition 

 

    leaf interface {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:interface-name"; 
      }
    }

Here the changes

 

test-complex-xpath/src/yang$ diff -c test-complex-xpath.yang.orig test-complex-xpath.yang
*** test-complex-xpath.yang.orig        Fri Jun 17 02:51:02 2022
--- test-complex-xpath.yang     Fri Jun 17 03:52:36 2022
***************
*** 32,38 ****

      leaf interface {
        type leafref {
!         path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration[ifmgr-cfg:active,ifmgr-cfg:interface-name]";
        }
      }
    }
--- 32,38 ----

      leaf interface {
        type leafref {
!         path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:interface-name";
        }
      }
    }

 

 

View solution in original post

absabry
Cisco Employee
Cisco Employee

Hello @douglasfir ,

 

Your path is referring to two values:

  • active
  • interface-name

And it cannot refer back to just one leaf interface.

 

You can either refer to both of them in separate leafs if you need them, something similar to this:

    leaf active-state {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../pe]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:active";
      }
    }
    leaf intf-name {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../pe]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:interface-name";
      }
    }

And it would list you all the configured values for both of these leafs.

 

On the other hand if you want to access to some values inside the interface itself, you can do something similar to this:

 

    leaf intf-desc {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../pe]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:description";
      }
    }

If you try to reference to your leaf two values, you'll get errors like these:

    leaf intf {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../pe]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration";
      }
    }

Error:

Error: the leafref refers to non-leaf and non-leaf-list node 'interface-configuration' in module 'Cisco-IOS-XR-ifmgr-cfg' at ../../cisco-iosxr/src/ncsc-out/modules/yang/Cisco-IOS-XR-ifmgr-cfg.yang:324

I hope this answers to your question.

 

Regards,

/Abdellah

View solution in original post

9 Replies 9

ygorelik
Cisco Employee
Cisco Employee

You can try this:

path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration[ifmgr-cfg:active,ifmgr-cfg:interface-name]";   

Yan

NSO architecture support 

Hi Yan,

 

sorry for the late response. I have tried to test the path using the following YANG model, but I get the error again:

 

module test-complex-xpath {
  namespace "http://com/example/testcomplexxpath";
  prefix test-complex-xpath;

  import ietf-inet-types {
    prefix inet;
  }
  import tailf-ncs {
    prefix ncs;
  }

  import Cisco-IOS-XR-ifmgr-cfg {
    prefix ifmgr-cfg;
  }

  augment /ncs:services {
  list test-complex-xpath {
    key name;

    uses ncs:service-data;
    ncs:servicepoint "test-complex-xpath";

    leaf name {
      type string;
    }

    leaf router {
      type leafref {
        path "/ncs:devices/ncs:device/ncs:name";
      }
    }

    leaf interface {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration[ifmgr-cfg:active,ifmgr-cfg:interface-name]"; 
      }
    }
  }
  }
}

The error is:

/home/ncs/nso-5.4.4.1/bin/ncsc `ls test-complex-xpath-ann.yang  > /dev/null 2>&1 && echo "-a test-complex-xpath-ann.yang"` \
        --fail-on-warnings \
        --yangpath /home/ncs/nso-use-cases/neds/asr9k-nc-7.1.3/src/ncsc-out/modules/yang \
        -c -o ../load-dir/test-complex-xpath.fxs yang/test-complex-xpath.yang
yang/test-complex-xpath.yang:35: error: bad argument value "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration[ifmgr-cfg:active,ifmgr-cfg:interface-name]", should be of type path-arg
make: *** [Makefile:29: ../load-dir/test-complex-xpath.fxs] Error 1

In the end I decided to go without this path, becase of switching to CLI NED for IOS XR, but it would be interesting to know how to reference the node when the key is made of two or more fields maybe for some future use case...

Thanks anyway!

Best regards,

Dragan

 

Hey

.../vty-access-list[seq-num='1'][ip-network='1.1.1.0/24']

Combined keys are printed like this in xpath, I'm almost sure same thing can be done for leafrefs too.

Hi u.avsec,

did you maybe try something based on this in the YANG model? These combined keys can be seen like you said when listing the configuration in CLI using "| display xpath", but unfortunately they don't seem to work in leafref path...

Thanks anyway!

Hey,

This is something that I had to figure out yesterday and it works:

          type leafref {
            path "../../element-drivers[type=current()/../ned-type][operating-system=current()/../operating-system]/ned-versions";
          }

This is done with YANG 1.0 on NSO 5.8.1. List element-drivers has combined keys type and operating-system and the ned-versions I am pointing to is a leaf-list. I also noticed that referencing keys has to be done with other nodes only. I tried to hardcode type='cli' string and I got and error.

It is not exactly what you want as I am referencing other node based on the keys but maybe it can help.

Nabsch
Spotlight
Spotlight

Hello,

 

The best way to find the xpath easier is to too use an existing interface then you do a 

show running devices device <yourdevice>config ... | display xpath 

 

 

 

I manage to compile but since i'am not using Netconf on XR device i cannot test if the leafref is working correctly.

 

Can you change your leaf  to this definition 

 

    leaf interface {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:interface-name"; 
      }
    }

Here the changes

 

test-complex-xpath/src/yang$ diff -c test-complex-xpath.yang.orig test-complex-xpath.yang
*** test-complex-xpath.yang.orig        Fri Jun 17 02:51:02 2022
--- test-complex-xpath.yang     Fri Jun 17 03:52:36 2022
***************
*** 32,38 ****

      leaf interface {
        type leafref {
!         path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration[ifmgr-cfg:active,ifmgr-cfg:interface-name]";
        }
      }
    }
--- 32,38 ----

      leaf interface {
        type leafref {
!         path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:interface-name";
        }
      }
    }

 

 

Hi @Nabsch ,

I have tried this approach, the YANG model indeed gets compiled this time, but the error is detected once I try to import it into NSO:

 

Error: Failed to load ./state/packages-in-use/3/test-complex-xpath/load-dir/test-complex-xpath.fxs: Module test-complex-xpath: The targets of the leafref path for node /services/test-complex-xpath/interface differ in type

 

However, it seems that there is another issue now, as this approach works fine with ifmgr-active only, as @absabry suggested:

      leaf active-state {
        type leafref {
          path "/ncs:devices/ncs:device[ncs:name=current()/../router]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:active";
        }
      }

I looked into the Cisco-IOS-XR-ifmgr-cfg.yang to compare active and interface-name leafs and the only difference that I see is that data type for interface-name is defined in another YANG module (Cisco-IOS-XR-types), so maybe this somehow is not recognized by NSO properly?

...
  import Cisco-IOS-XR-types {
    prefix xr;
  } 
...
     leaf active {
        type Interface-active;
        description
          "Whether the interface is active or
           preconfigured";
      }
      leaf interface-name {
        type xr:Interface-name;
        description
          "The name of the interface";
      }
...

absabry
Cisco Employee
Cisco Employee

Hello @douglasfir ,

 

Your path is referring to two values:

  • active
  • interface-name

And it cannot refer back to just one leaf interface.

 

You can either refer to both of them in separate leafs if you need them, something similar to this:

    leaf active-state {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../pe]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:active";
      }
    }
    leaf intf-name {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../pe]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:interface-name";
      }
    }

And it would list you all the configured values for both of these leafs.

 

On the other hand if you want to access to some values inside the interface itself, you can do something similar to this:

 

    leaf intf-desc {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../pe]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration/ifmgr-cfg:description";
      }
    }

If you try to reference to your leaf two values, you'll get errors like these:

    leaf intf {
      type leafref {
        path "/ncs:devices/ncs:device[ncs:name=current()/../pe]/ncs:config/ifmgr-cfg:interface-configurations/ifmgr-cfg:interface-configuration";
      }
    }

Error:

Error: the leafref refers to non-leaf and non-leaf-list node 'interface-configuration' in module 'Cisco-IOS-XR-ifmgr-cfg' at ../../cisco-iosxr/src/ncsc-out/modules/yang/Cisco-IOS-XR-ifmgr-cfg.yang:324

I hope this answers to your question.

 

Regards,

/Abdellah

Hi @absabry ,

thanks for you answer. I have tried the approach and it works fine for active leaf, but for the interface-name leaf it is reporting the error, as mentioned in the reply to @Nabsch above. I looked into the Cisco-IOS-XR-ifmgr-cfg YANG model to compare the data types for both and I am not sure if it has something with NSO not being able to properly interpret data type defined in another YANG model for interface-name, while for active leaf it works fine, as the type definition is inside the same YANG model...

I did one more test now with the YANG model Cisco-IOS-XR-um-interface-cfg which uses the same data type for interface-name as in "legacy" model Cisco-IOS-XR-ifmgr-cfg. This time there was not issue...do you have maybe some idea what might be the problem here? Maybe I could opent a separate thread for this?

Regards!

Dragan