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

pyang Default path for yang files

DTtb
Level 1
Level 1

If I try to validate with pyang my YANG-model with imported submodules, I need to specify the path to the external submodules.

For the built-in yang-models, like ietf-inet-types, I don't need to specify the path.

But the man-page of pyang describes following:

See http://www.yang-central.org/twiki/pub/Main/YangTools/pyang.1.html

The following directories are always added to the search path:

  1. current directory

  2. $YANG_MODPATH

  3. $HOME/yang/modules

  4. $YANG_INSTALL/yang/modules OR if $YANG_INSTALL is unset <the default installation directory>/yang/modules (on Unix systems: /usr/share/yang/modules)

 

 

 

 

module my-module {
namespace "http://test.com/my-module";
prefix mymodule;

import ietf-inet-types {
prefix inet;
}
import tailf-common {
prefix tailf;
}
import tailf-ncs {
prefix ncs;
}
import private-module {
prefix private;
}
//yang code ...
}
[root@c945565b350c yang]# pyang my-module.yang
my-module.yang:15: error: module "private-module" not found in search path
[root@c945565b350c yang]#

So, the default path for the built-in yang modules is /ncs/src/yang/.

 

Does NSO exposed the path to the built-in yang modules to pyang?

 

Thanks

 

 

1 Accepted Solution

Accepted Solutions

gmuloche
Cisco Employee
Cisco Employee

Hello,

 

It depends what pyang you are using. If you type which pyang and it returns you some bin in $NCS_DIR/bin/pyang then this is a script which wraps pyang contained inside NSO and will set/add to the following env variables (snippet):

13 pyang=$ncsdir/lib/pyang/bin/pyang
14
15 if [ "x${PYTHONPATH}" != "x" ]; then
16 PYTHONPATH=$ncsdir/lib/pyang:$PYTHONPATH
17 else
18 PYTHONPATH=$ncsdir/lib/pyang
19 fi
20 if [ "x${YANG_MODPATH}" != "x" ]; then
21 YANG_MODPATH=$ncsdir/src/ncs/yang:$YANG_MODPATH
22 else
23 YANG_MODPATH=$ncsdir/src/ncs/yang
24 fi
25 export PYTHONPATH YANG_MODPATH
26
27 exec $pyang "$@"

So it is setting the YANG_MODPATH variable to a folder where the built-in module resides and according to the man page they will be used. So the answer is "yes, the wrapper script `pyang` in NSO is exposing the built-in modules"

 

 

Regards,

--

Guillaume

 

 

View solution in original post

1 Reply 1

gmuloche
Cisco Employee
Cisco Employee

Hello,

 

It depends what pyang you are using. If you type which pyang and it returns you some bin in $NCS_DIR/bin/pyang then this is a script which wraps pyang contained inside NSO and will set/add to the following env variables (snippet):

13 pyang=$ncsdir/lib/pyang/bin/pyang
14
15 if [ "x${PYTHONPATH}" != "x" ]; then
16 PYTHONPATH=$ncsdir/lib/pyang:$PYTHONPATH
17 else
18 PYTHONPATH=$ncsdir/lib/pyang
19 fi
20 if [ "x${YANG_MODPATH}" != "x" ]; then
21 YANG_MODPATH=$ncsdir/src/ncs/yang:$YANG_MODPATH
22 else
23 YANG_MODPATH=$ncsdir/src/ncs/yang
24 fi
25 export PYTHONPATH YANG_MODPATH
26
27 exec $pyang "$@"

So it is setting the YANG_MODPATH variable to a folder where the built-in module resides and according to the man page they will be used. So the answer is "yes, the wrapper script `pyang` in NSO is exposing the built-in modules"

 

 

Regards,

--

Guillaume