yangmap External Interface
The yangmap feature allows one YANG model to be mapped to another YANG model to simplify or stabilize the client-facing command interface, in “config term” mode.
+--------------+ +---------+ +--------------+
| source model | <-> | yangmap | <-> | target model |
+--------------+ +---------+ +--------------+
Each yangmap file contains the following information
source module name(s)
target module name(s)
automap flag
set of nodemaps (source to target)
set of keymaps (source to target key)
set of childmaps (source to target leaf)
When a yangmap is active, the source model will be used if the target models are supported in a session.
If the server advertises all the target modules in the yangmap, then these modules will be hidden in config term mode.
Instead, the source models will be injected into the session and these modules will be used instead of the target modules.
The “show modules” and “show objects” commands will hide the target modules.
--yangmap CLI Parameter
The --yangmap CLI parameter specifies a YANG mapping file that contains a <yangmap> instance document.
This can be placed in the yangcli-pro.conf config file.
This mapping is used to convert the source model to the target model. There is no support at this time to convert the target model to the source model.
leaf-list yangmap {
description
"Specifies a yangmap XML file that should be loaded
into the program. See yumaworks-yangmap.yang for
details on using YANG mappings in config term mode.";
type string; // filespec
}
Example yangcli-pro.conf:
yangcli-pro {
yangmap /home/lab/yangmaps/test-ex1-yangmap.xml
}
yumaworks-yangmap YANG Module
The yumaworks-yangmap.yang module contains the data structures used for this feature.
yangmap Example
This simple example shows how the yangmap feature is configured and used.
Source Model
The YANG module 'test-ex2.yang' is used as the source model:
module test-ex2 {
namespace "http://yumaworks.com/ns/test-ex2";
prefix "e2";
description
"Example sourcet module for yangmap
test-ex1-yangmap.xml creates the following mapping:
logicalp -> /logical-ports/logical-port
id -> name
nest -> nest2
A -> name
B -> N2
C -> N3
";
revision 2018-02-22;
// test source (client-facing) data model
list logicalp {
key "id"; // map to name in test-ex1
leaf id { type string; }
list nest {
key A;
leaf A { type string; }
leaf B { type int32; }
leaf C { type uint32; }
}
}
}
Target Model
The YANG module 'test-ex1.yang' is used as the target model:
module test-ex1 {
namespace "http://yumaworks.com/ns/test-ex1";
prefix "e1";
description
"Example target module for yangmap";
revision 2018-02-22;
// test target (hidden from client) data model
container logical-ports {
list logical-port {
key "name";
leaf name { type string; }
list nest2 {
key name;
leaf name { type string; }
leaf N2 { type int32; }
leaf N3 { type uint32; }
}
}
}
}
YANGMAP File
The XML file 'test-ex1-yangmap.xml' contains the mapping information for this yangmap:
<yangmap>
<source-module>test-ex2</source-module>
<target-module>test-ex1</target-module>
<nodemap>
<source-node>/test-ex2:logicalp</source-node>
<target-node>/test-ex1:logical-ports/logical-port</target-node>
<target-keys>
<keymap>
<key-node>/test-ex1:logical-ports/logical-port/name</key-node>
<source-node>/test-ex2:logicalp/id</source-node>
</keymap>
</target-keys>
</nodemap>
<nodemap>
<source-node>/test-ex2:logicalp/nest</source-node>
<target-node>/test-ex1:logical-ports/logical-port/nest2</target-node>
<target-keys>
<keymap>
<key-node>/test-ex1:logical-ports/logical-port/name</key-node>
<source-node>/test-ex2:logicalp/id</source-node>
</keymap>
<keymap>
<key-node>/test-ex1:logical-ports/logical-port/nest2/name</key-node>
<source-node>/test-ex2:logicalp/nest/A</source-node>
</keymap>
</target-keys>
<childmap>
<source-child>B</source-child>
<target-node>/test-ex1:logical-ports/logical-port/nest2/N2</target-node>
</childmap>
<childmap>
<source-child>C</source-child>
<target-node>/test-ex1:logical-ports/logical-port/nest2/N3</target-node>
</childmap>
</nodemap>
</yangmap>