cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1123
Views
5
Helpful
1
Replies

YANG: Using single absolute path for referencing a leaf from different hierarchy levels

dvulovic
Cisco Employee
Cisco Employee

Hi,

 

I want to create a NSO service that uses grouping from 3rd party YANG model. However, this model uses a lot of absolute leafref path references that need to be changed. Although it could be done manually with substantial effort, I would like to explore the possibility to use simple text replacement to convert references from the existing path to the new path.

 

In generic YANG, service model would be something like:

 

module svc {

  import a { prefix a; }

  list svc { 

    key id;
    leaf id { type string; }

    container a { uses a:a-grouping; }
  }
}

 

Original 3rd party module "a" is something like:

 

module a {

  grouping a-grouping {

    leaf target1 { type string }

    container c1 {

      leaf target2 { type string; }

      leaf ref1 { type leafref { path "/a/target1"; } }

      container c2 {

        leaf ref2 { type leafref { path "/a/target1"; } }
        leaf ref3 { type leafref { path "/a/c1/target2"; } }
       }
     }
    }
  }

  container a { uses a:a-grouping; } }
}

 

The question is - can I replace "/a" with some string that would work in NSO service context? One theoretical possibility is to use XPath "ancestor" axis (i.e. to change "/a/target1" to something like "ancestor::svc/c/target1") but I couldn't make it work by myself.

 

Thanks in advance!

1 Reply 1

Jan Lindblad
Cisco Employee
Cisco Employee

Djordje,

 

I want to create a NSO service that uses grouping from 3rd party YANG model. However, this model uses a lot of absolute leafref path references that need to be changed. Although it could be done manually with substantial effort, I would like to explore the possibility to use simple text replacement to convert references from the existing path to the new path.


You can of course always create a new module of your own that has similar content to an existing module. This new module could very well be created using string substitution mechanisms. You should ensure that you use your own namespace (and probably prefix) if you do this, however. We don't want two modules in the world with the same namespace name but different content. You should also be aware that doing so may be a copyright infringement. Get permission from the original author. It's also not clear that branching a standard is a good thing for the standard.

 

From your quoted example, I'm not sure why keeping /a would not work. You can have YANG modules mounted pretty much wherever you like in NSO, except *device* YANG models, which have to go under /devices/device/... If you could keep the original module under /a, that may save you a bit of work, legal trouble and stay true to the standard you are implementing.

 

One theoretical possibility is to use XPath "ancestor" axis (i.e. to change "/a/target1" to something like "ancestor::svc/c/target1") but I couldn't make it work by myself.

I would not recommend using any XPath axis. They tend to be not interoperable and often very slow.

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: