The YANG file can be altered, either directly (by editing) or indirectly (via deviation statements), and the new or altered default value specified there. In addition, range statements, patterns, XPath expressions, and all other machine-readable statements are all processed automatically, so the YANG statements themselves are like server source code. YANG also allows vendor and platform-specific deviations to be specified, which are like generic patches to the common YANG module for whatever purpose needed. YANG also allows annotations to be defined and added to YANG modules, which are specified with the 'extension' statement. YumaPro uses some extensions to control some automation features, but any module can define extensions, and  module instrumentation code can access these annotations during server operation, to control device behaviour.


This article illustrates how to define annotation and deviation modules and what server CLI parameters should be used to load those modules:


The --deviation parameter is a leaf-list of modules that should be loaded automatically when the program starts, as a deviation module. In this mode, only the deviation statements are parsed and then made available later when the module that contains the objects being deviated is parsed. The deviations must be known to the parser before the target module is parsed. This parameter is used to identify any modules that have deviation statements for the set of modules being parsed (e.g., --module and --subtree parameters). A module can be listed with both the --module and --deviation parameters, but that is not needed unless the module contains external deviations. If the module only contains deviations for objects in the same module, then the --deviation parameter does not need to be used. The program will attempt to load each module in deviation parsing mode, in the order the parameters are entered. For the netconfd-pro program, If any modules have fatal errors then the program will terminate. For the yangdump-pro and yangcli-pro programs, each module will be processed as requested.

The following example module shows how deviations could be added to the ietf-interfaces module.


module test1_deviations {
  namespace "http://netconfcentral.org/ns/test1_deviations";
  prefix "test1_deviations";

  import ietf-interfaces { prefix if; }

  revision "2017-04-10";

  deviation /if:interfaces/if:interface/if:somenode {
    deviate add {
     must "(true() = contains(../if:name,'interface1')) or "
         + "(true() = contains(../if:name,'interface2')) or "
         + "(true() = contains(../if:name,'interface3'))" {

         error-message "Custom Error Message";
      }
    }
  }

  deviation /if:interfaces/if:interface/if:somenode2 {
    deviate add {

      must "starts-with(string(../if:type), 'test') or "
         + "starts-with(string(../if:type), 'not-test') " {

        error-message "Custom Error Message";
      }
    }
  }

  deviation /if:interfaces/if:interface/if:somenode3 {
    deviate replace {
      type uint16;
    }
  }

  deviation /if:interfaces/if:interface/if:somenode4 {
    deviate not-supported;
  }

}


--deviation parameter


Syntax
string
Default:
none
Min Allowed:
0
Max Allowed:
unlimited
Supported by:
netconfd-pro
yangcli-pro
yangdump-pro
Example:
netconfd-pro --deviation=test1_deviations


The --annotation parameter is a leaf-list of modules that should be loaded automatically when the program starts, as a deviation module containing annotations. In this mode, only the deviation statements are parsed and then made available later when the module that contains the objects being deviated is parsed. The annotation file is not advertised to clients or shown in the YANG library. The program will attempt to load each module in annotation parsing mode, in the order the parameters are entered. All deviation parameters will be processed, then all annotation parameters. An annotation module is just a YANG module that contains only 'deviation' statements with “deviate add” sub-statements. 

The following example module shows how annotations could be added to the ietf-interfaces module.


module devtest1-d {
  namespace "http://netconfcentral.org/ns/devtest1-d";
  prefix dt1-d;

  import ietf-interfaces { prefix if; }
  import yuma-ncx { prefix ncx; }

  revision "2016-04-10";

  deviation /if:interfaces {
    deviate add {
      ncx:sil-delete-chilren-first;
    }
  }

  deviation /if:interfaces/if:interface {
    deviate add {
      ncx:sil-delete-chilren-first;
    }
  }
}


--annotation parameter


Syntax
string
Default:
none
Min Allowed:
0
Max Allowed:
unlimited
Supported by:
netconfd-pro
Example:
netconfd-pro –annotation=devtest1-d