Example Data Models and Instances
Doctest snippets in this documentation use the following example data models and their JSON-encoded instances.
Example 1
Schema Tree
+--rw example-1:greeting? <string>
This example is used in the documentation of the datamodel
module.
YANG Library
File: examples/ex1/yang-library-ex1.json
{
"ietf-yang-library:modules-state": {
"module-set-id": "ae4bf1ddf85a67ab94a9ab71593cd1c78b7f231d",
"module": [
{
"name": "example-1",
"namespace": "http://example.com/example-1",
"revision": "",
"conformance-type": "implement"
}
]
}
}
YANG Module example-1
File: examples/ex1/example-1.yang
module example-1 {
yang-version 1.1;
namespace "http://example.com/example-1";
prefix ex1;
leaf greeting {
type string;
default "Hello, world!";
}
}
Instance document
File: examples/ex1/example-data.json
{
"example-1:greeting": "Hi!"
}
Example 2
This example is used in the documentation of the instance
module, and also in Quick Start.
Schema Tree
+--rw example-2:bag
+--rw bar <boolean>
+--rw baz? <decimal64>
+--rw foo# [number]
+--rw in-words? <string>
+--rw number <uint8>
+--rw prime? <boolean>
YANG Library
File: examples/ex2/yang-library-ex2.json
{
"ietf-yang-library:modules-state": {
"module-set-id": "9a9b7d2d28d4d78fa42e12348346990e3fb1c1b9",
"module": [
{
"name": "example-2",
"namespace": "http://example.com/example-2",
"revision": "",
"deviation": [
{ "name": "example-2-dev",
"revision": ""
}
],
"conformance-type": "implement"
},
{
"name": "example-2-dev",
"namespace": "http://example.com/example-2-dev",
"revision": "",
"conformance-type": "implement"
},
{
"name": "ietf-yang-metadata",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-yang-metadata",
"revision": "2016-08-05",
"conformance-type": "implement"
},
{
"name": "ietf-origin",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-origin",
"revision": "2018-02-14",
"conformance-type": "implement"
}
]
}
}
YANG Module example-2
File: examples/ex2/example-2.yang
module example-2 {
yang-version 1.1;
namespace "http://example.com/example-2";
prefix ex2;
container bag {
list foo {
key "number";
ordered-by user;
unique "in-words";
leaf number {
type uint64;
}
leaf prime {
type boolean;
}
leaf in-words {
type string {
pattern "[a-z][a-z\\-]+[a-z]" {
error-message "must be number in words";
}
}
}
leaf unlucky {
type boolean;
default "false";
}
}
leaf bar {
type boolean;
config false;
mandatory true;
}
leaf baz {
when "not(../foo/in-words = 'forty-two')";
type decimal64 {
fraction-digits 7;
}
default "0";
}
}
}
YANG Module example-2-dev (deviations)
File: examples/ex2/example-2-dev.yang
module example-2-dev {
namespace "http://example.com/example-2-dev";
prefix ex2d;
import example-2 {
prefix ex2;
}
deviation "/ex2:bag/ex2:foo/ex2:unlucky" {
deviate not-supported;
}
deviation "/ex2:bag/ex2:foo/ex2:prime" {
deviate add {
default "false";
}
}
}
Instance document
File: examples/ex2/example-data.json
{
"example-2:bag": {
"foo": [
{
"number": "6",
"in-words": "six"
},
{
"@": {
"ietf-origin:origin": "ietf-origin:system"
},
"number": "3",
"prime": true,
"in-words": "three"
},
{
"number": "7",
"prime": true,
"in-words": "seven"
},
{
"number": "8",
"in-words": "eight"
}
],
"bar": true
}
}
The same instance document in YAML representation is used in Quick Start:
File: examples/ex2/example-data.yaml
example-2:bag:
bar: true
foo:
- in-words: six
number: "6"
- '@':
ietf-origin:origin: ietf-origin:system
in-words: three
number: "3"
prime: true
- in-words: seven
number: "7"
prime: true
- in-words: eight
number: "8"
Example 3
This example is used in the documentation of the schemadata
module.
Schema Tree
+--rw example-3-a:top
+--rw bar? <string>
+--rw example-3-b:bar? <string>
+--rw baz? <ipv4-address-no-zone(string)>
+--rw example-3-b:baz? <port-number(uint16)>
+--rw foo? <empty>
+--rw quux? <uint8>
YANG Library
File: examples/ex3/yang-library-ex3.json
{
"ietf-yang-library:modules-state": {
"module-set-id": "5798f6c8acd78ccb1171cb36d34fb95ca797c769",
"module": [
{
"name": "example-3-a",
"feature": [
"fea1",
"fea2"
],
"namespace": "http://example.com/example-3/a",
"revision": "2017-08-01",
"conformance-type": "implement",
"submodule": [
{
"name": "example-3-suba",
"revision": "2017-08-01"
}
]
},
{
"name": "example-3-b",
"namespace": "http://example.com/example-3/b",
"revision": "2016-08-22",
"conformance-type": "implement"
},
{
"name": "ietf-inet-types",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-inet-types",
"revision": "2010-09-24",
"conformance-type": "import"
},
{
"name": "ietf-yang-types",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-yang-types",
"revision": "2013-07-15",
"conformance-type": "import"
},
{
"name": "ietf-inet-types",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-inet-types",
"revision": "2013-07-15",
"conformance-type": "import"
}
]
}
}
YANG Module example-3-a
File: examples/ex3/example-3-a@2017-08-01.yang
module example-3-a {
yang-version 1.1;
namespace "http://example.com/example-3/a";
prefix ex3a;
import ietf-yang-types {
prefix yang;
}
include example-3-suba {
revision-date 2017-08-01;
}
revision 2017-08-01;
feature fea1;
feature fea2;
identity idX;
grouping gbar {
leaf bar {
type string;
}
}
container top {
uses gquux;
leaf foo {
if-feature "fea1";
type empty;
}
}
}
YANG Submodule example-3-suba
File: examples/ex3/example-3-suba@2017-08-01.yang
submodule example-3-suba {
yang-version 1.1;
belongs-to example-3-a {
prefix ex3a;
}
import ietf-inet-types {
prefix inet;
revision-date 2013-07-15;
}
revision 2017-08-01;
grouping gquux {
leaf quux {
type uint8;
}
}
augment "/ex3a:top" {
uses gbar;
leaf baz {
if-feature "fea2";
type inet:ipv4-address-no-zone;
}
}
}
YANG Module example-3-b
File: examples/ex3/example-3-b@2016-08-22.yang
module example-3-b {
yang-version 1.1;
namespace "http://example.com/example-3/b";
prefix ex3b;
import ietf-inet-types {
prefix oin;
revision-date 2010-09-24;
}
import example-3-a {
prefix ex3a;
}
revision 2016-08-22;
identity idY;
identity idZ {
base ex3a:idX;
base idY;
}
augment "/ex3a:top" {
if-feature "ex3a:fea1 or ex3a:fea2";
uses ex3a:gbar;
leaf baz {
type oin:port-number;
}
}
}
Example 4
This example is used in the documentation of
the schemanode
, xpathast
and xpathparser
modules.
Schema Tree
+--rw example-4-a:bag!
| +--ro bar? <boolean>
| x--rw foo <uint8>
| +--rw (opts)?
| +--:(a)
| | +--rw baz? <empty>
| +--:(example-4-b:fooref)
| +--rw fooref? <leafref>
+--rw example-4-b:quux# <decimal64>
YANG Library
File: examples/ex4/yang-library-ex4.json
{
"ietf-yang-library:modules-state": {
"module-set-id": "b5e2c7aa84bd40f60c853ceefb69031ed8f9b96b",
"module": [
{
"name": "example-4-a",
"namespace": "http://example.com/example-4-a",
"revision": "",
"conformance-type": "implement"
},
{
"name": "example-4-b",
"namespace": "http://example.com/example-4-b",
"revision": "",
"conformance-type": "implement"
},
{
"name": "ietf-yang-metadata",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-yang-metadata",
"revision": "2016-08-05",
"conformance-type": "implement"
},
{
"name": "ietf-origin",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-origin",
"revision": "2018-02-14",
"conformance-type": "implement"
},
{
"name": "ietf-yang-types",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-yang-types",
"revision": "2013-07-15",
"conformance-type": "import"
},
{
"name": "ietf-netconf-acm",
"namespace": "urn:ietf:params:xml:ns:yang:ietf-netconf-acm",
"revision": "2018-02-14",
"conformance-type": "import"
}
]
}
}
YANG Module example-4-a
File: examples/ex4/example-4-a.yang
module example-4-a {
yang-version 1.1;
namespace "http://example.com/example-4-a";
prefix ex4a;
import ietf-netconf-acm {
prefix nacm;
revision-date 2018-02-14;
}
container bag {
description "Top-level container.";
presence "true";
leaf foo {
type uint8;
units "foondela";
mandatory true;
status deprecated;
nacm:default-deny-write;
}
leaf bar {
type boolean;
mandatory "true";
config false;
}
choice opts {
default "a";
case a {
leaf baz {
type empty;
}
}
}
}
}
YANG Module example-4-b
File: examples/ex4/example-4-b.yang
module example-4-b {
yang-version 1.1;
namespace "http://example.com/example-4-b";
prefix ex4b;
import example-4-a {
prefix ex4a;
}
leaf-list quux {
type decimal64 {
fraction-digits 4;
}
default 2.7182;
max-elements 2;
ordered-by user;
}
augment "/ex4a:bag/ex4a:opts" {
when "/ex4b:quux = 0";
leaf fooref {
type leafref {
path "../ex4a:foo";
}
}
}
}
Instance document
File: examples/ex4/example-data.json
{
"example-4-a:bag": {
"foo": 42,
"bar": false,
"example-4-b:fooref": 42
},
"example-4-b:quux": [
"3.1415",
"0"
]
}
Example 5
This example is used in the documentation of the datatype
and
statement
modules.
Schema Tree
+--rw example-5-a:binary-leaf? <binary>
+--rw example-5-a:bits-leaf? <bits>
+--rw example-5-a:boolean-leaf? <boolean>
+--rw example-5-a:decimal64-leaf? <decimal64>
+--rw example-5-a:empty-leaf? <empty>
+--rw example-5-a:enumeration-leaf? <enumeration>
+--rw example-5-a:identityref-leaf? <identityref>
+--rw example-5-a:instance-identifier-leaf? <instance-identifier>
+--rw example-5-a:leafref-leaf? <leafref>
+--rw example-5-a:string-leaf? <my-string(string)>
+--rw example-5-a:union-leaf? <union>
YANG Library
File: examples/ex5/yang-library-ex5.json
{
"ietf-yang-library:modules-state": {
"module-set-id": "d540849211ed999e1d41f89f2d6353d26f0b2915",
"module": [
{
"name": "example-5-a",
"namespace": "http://example.com/example-5-a",
"revision": "2018-10-25",
"conformance-type": "implement"
},
{
"name": "example-5-b",
"namespace": "http://example.com/example-5-b",
"revision": "",
"conformance-type": "implement"
}
]
}
}
YANG Module example-5-a
File: examples/ex5/example-5-a.yang
module example-5-a {
yang-version 1.1;
namespace "http://example.com/example-5-a";
prefix ex5a;
import example-5-b {
prefix ex5b;
}
revision 2018-10-25;
typedef my-string {
type string {
length "2..4";
pattern "x*y" {
error-message "xes and y";
}
}
default "xxy";
}
leaf binary-leaf {
type binary;
}
leaf bits-leaf {
type bits {
bit un {
position 1;
}
bit dos;
bit tres;
}
}
leaf boolean-leaf {
type boolean;
}
leaf decimal64-leaf {
type decimal64 {
fraction-digits 4;
}
}
leaf empty-leaf {
type empty;
}
leaf enumeration-leaf {
type enumeration {
enum Bashful;
enum Doc;
enum Dopey;
enum Grumpy;
enum Happy;
enum Sleepy;
enum Sneezy;
}
}
leaf identityref-leaf {
type identityref {
base ex5b:base-identity;
}
default "ex5b:derived-identity";
}
leaf instance-identifier-leaf {
type instance-identifier;
}
leaf leafref-leaf {
type leafref {
path "/string-leaf";
require-instance true;
}
}
leaf string-leaf {
type my-string;
}
leaf union-leaf {
type union {
type my-string;
type boolean;
}
}
}
YANG Module example-5-b
File: examples/ex5/example-5-b.yang
module example-5-b {
yang-version 1.1;
namespace "http://example.com/example-5-b";
prefix ex5b;
identity base-identity;
identity derived-identity {
base base-identity;
}
}