mbj4668 / pyang

An extensible YANG validator and converter in python
ISC License
530 stars 343 forks source link

printing a tree for a module that is augmented by other modules? #764

Open hellt opened 2 years ago

hellt commented 2 years ago

Hi pyang maintainers/users, I wonder what is the correct way to print a -f tree representation of a module which containers are augmented by other modules?

The case in point I have is represented with the following yang files

srl_nokia/models/interfaces
├── srl_nokia-if-ip.yang
├── srl_nokia-if-mpls.yang
├── srl_nokia-interfaces-lag.yang
├── srl_nokia-interfaces.yang
├── srl_nokia-lacp.yang

The main module is contained within a file srl_nokia-interfaces.yang and other modules in this directory provides augmentation for it.

For example a snippet from srl_nokia-interfaces-lag.yang:

module srl_nokia-interfaces-lag {
  yang-version 1.1;

  // namespace
  namespace "urn:srl_nokia/interfaces/lags";

  prefix "srl_nokia-if-lag";

  import srl_nokia-interfaces { prefix srl_nokia-if; }
  import srl_nokia-extensions { prefix srl_nokia-ext; }
  import srl_nokia-common { prefix srl_nokia-comm; }
  import srl_nokia-features { prefix srl_nokia-feat; }

 grouping lag-logical-config {
 <some model>
 }

  augment "/srl_nokia-if:interface" {
    uses lag-logical-config;
  }
}

With such a composition of a modules, how do I process the main srl_nokia-interfaces.yang module that it will have all the augmentations?

The only option that seems to work for me is to explicitly load all the yang files like that

pyang -p <some search paths> -f tree ./*.yang --tree-path interface

Is it the (only) correct way?

mbj4668 commented 2 years ago

Yes this looks correct.

hellt commented 2 years ago

Thanks @mbj4668 Is there a way to then limit the output to only the single module that is augmented by many?

I.e. if I have module A which is augmented by modules B C D, how can I print with tree/jstree only the module A and not the rest?

There is tree-path for tree output, but if the path happens to be not only in module A I still get several modules...

GermanoSMO commented 2 years ago

You may try using the "--deviation" clause to invoke only the augmenting modules

pyang -f tree -o mytree.txt --deviation=srl_nokia-if-ip.yang --deviation=srl_nokia-if-mpls.yang .... srl_nokia-interfaces.yang

This should produce what you expect

hellt commented 2 years ago

Thanks @GermanoSMO that will require me to know which modules augment a certain module. Unfortunately I do not have this information beforehand.

What we ended up doing is creating a post-processing script that removes modules that doesn't have nodes of its own (these are the modules which only contain augment instruction) from the resulting output