Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

YANG Metadata Annotations for Junos Devices

Junos devices support YANG extensions that define metadata annotations, which you can use to perform specific operations on the Junos configuration.

Junos devices support YANG extensions to annotate instances of YANG data nodes with metadata. You can use the following extensions on supported devices:

  • junos-configuration-metadata—Juniper annotations that you can use to perform specific configuration operations.

  • openconfig-metadata—Annotations defined by the OpenConfig working group.

YANG metadata annotations and their corresponding JSON and XML encoding are defined in RFC 7952, Defining and Using Metadata with YANG. The ietf-yang-metadata module defines the YANG extension annotation.

Note:

YANG metadata annotations should not be confused with Junos configuration annotations, which are comments that are included in the configuration, for example, by using the annotate configuration mode command.

junos-configuration-metadata Module Overview

The Juniper Networks junos-configuration-metadata module defines metadata annotations that enable you to perform specific operations on the Junos configuration.

Devices that support the junos-configuration-metadata annotations advertise the following capabilities in the NETCONF capabilities exchange:

Table 1 outlines the junos-configuration-metadata annotations. The annotations use the http://yang.juniper.net/junos/jcmd namespace URI and the jcmd namespace prefix.

Table 1: junos-configuration-metdata Annotations
Annotation Value Description
active false

Deactivate the specified configuration statement. The statement remains in the configuration but does not affect the device's operation.

true

Activate the specified configuration statement. Use this annotation to activate a statement that was previously deactivated.

comment string

Add a comment with additional information about the specified configuration statement, or remove an existing comment by setting the value to an empty string ("").

protect false

Remove any previously applied protect state from the specified configuration statement and allow changes to that statement.

true

Prevent future modifications to the specified statement, until such time that the protect state is removed.

Using junos-configuration-metadata Annotations in Configuration Data

You can use the junos-configuration-metadata annotations in a YANG-compliant NETCONF session to perform specific metadata operations on the configuration. Supported operations include adding comments to the configuration, deactivating or activating configuration hierarchies and statements, and protecting configuration hierarchies and statements, as described in the following sections:

You can apply junos-configuration-metadata annotations on a container (statement hierarchy), leaf-list, leaf statement, or a list item (statement with an identifier). When you apply the annotations on leaf-list statements, you can only apply them at the leaf-list level, not on individual leaf-list entries.

You can use the YANG annotations in JSON or XML configuration data, as outlined in Table 2. You can use the NETCONF <edit-config> operation to load XML configuration data, and you can use the Junos XML protocol <load-configuration> operation to load JSON or XML configuration data on a device.

Table 2: Using Configuration Metadata Annotations
Encoding Syntax Example

JSON (metadata object)

"module-name:annotation" : "value"

"junos-configuration-metadata:comment" : "comment string"

XML (XML attributes)

xmlns:prefix=namespace-uri

prefix:annotation="value"

<element-name xmlns:jcmd="http://yang.juniper.net/junos/jcmd" jcmd:comment="comment string">

Add Comments in the Configuration

You can use the comment annotation to add comments to a configuration statement. The following sections outline how to add a comment when loading JSON or XML configuration data.

JSON

To add a comment when loading JSON configuration data, include the junos-configuration-metadata:comment annotation in the metadata object for that statement and specify the comment as a string. To remove a comment, include an empty string ("").

The following example associates one comment with a hierarchy, another comment with a list entry that requires an identifier, and a third comment with an existing leaf statement.

XML

To add a comment when loading XML configuration data, include the jcmd:comment annotation as an XML attribute in the opening tag of that configuration element and specify the comment as a string. To remove a comment, include an empty string ("").

The following example associates one comment with a hierarchy, another comment with a list entry that requires an identifier, and a third comment with a leaf statement.

Activate or Deactivate Configuration Statements

You can use the active annotation to deactivate a configuration statement or to activate a configuration statement that was previously deactivated. To deactivate a statement, set active to false. To activate a statement, set active to true.

The following sections outline how to deactivate and activate configuration statements in JSON and XML configuration data.

JSON

To deactivate or reactivate a configuration object in JSON, include the "junos-configuration-metadata:active" : (false | true) annotation in the metadata object for that statement.

For example, the following RPC deactivates the [edit protocols isis] hierarchy, activates the apply-groups leaf-list statement, and modifies the specified event policy to deactivate the event-script action and reactivate the raise-trap action.

XML

To deactivate or reactivate a configuration object, include the jcmd:active="false" or jcmd:active="true" annotation, respectively, as an XML attribute in the opening tag of that configuration element.

The following RPC deactivates the [edit protocols isis] hierarchy, activates the apply-groups leaf-list statement, and modifies the specified event policy to deactivate the event-script action and reactivate the raise-trap action.

Protect or Unprotect Configuration Statements

You can protect selected Junos configuration hierarchies and statements to prevent changes to those statements until such time that the protect attribute is removed.

The following sections outline how to protect or unprotect configuration statements in JSON and XML configuration data.

JSON

To protect or unprotect a configuration object in JSON, include the "junos-configuration-metadata:protect" : (true | false) annotation in the metadata object for that statement.

For example, the following RPC protects the [edit protocols isis] hierarchy level, the apply-groups leaf-list statement, and the host-name leaf statement, and it removes the protect attribute for the specified event policy.

XML

To protect or unprotect a configuration object, include the jcmd:protect="true" or jcmd:protect="false" annotation, respectively, as an XML attribute in the opening tag of that configuration element.

The following RPC protects the [edit protocols isis] hierarchy level, the apply-groups leaf-list statement, and the host-name leaf statement, and it removes the protect attribute for the specified event policy.

openconfig-metadata Module Overview

The openconfig-metadata YANG module includes metadata annotations defined by the OpenConfig working group. The module defines the protobuf-metadata annotation, which enables you to store metadata about the configuration directly within the configuration for easy reference.

Junos devices support the openconfig-metadata:protobuf-metadata annotation with the following constraints:

  • You can configure only one protobuf-metadata annotation and only at the root level of the configuration hierarchy.

  • You can only configure and view the annotation in JSON configuration data.

  • The annotation is of type binary, but you must encode the binary value in the base64 encoding scheme before loading the annotation on the device.

Junos devices support configuring the openconfig-metadata:protobuf-metadata annotation by default. However, to enable the device to emit the capability in the NETCONF capabilities exchange and emit the annotation in the configuration data, you must configure the device as follows:

  1. Require the NETCONF server to advertise standard YANG modules, such as OpenConfig modules, in the capabilities exchange.

  2. Configure the device to enforce YANG-compliant NETCONF sessions.

  3. (Optional) Unhide the OpenConfig schema, if you intend to view OpenConfig statements, including the annotation, in the CLI.

  4. Commit the configuration.

After you configure the device to advertise standard YANG modules in the NETCONF capabilities exchange, devices that support openconfig-metadata annotations advertise the following capability in the hello message:

You use the gNMI set() operation to load the openconfig-metadata:protobuf-metadata annotation as part of your JSON configuration data.

When you request JSON configuration data, as described in View Metadata Annotations in Configuration Data, the output displays the OpenConfig configuration, including the annotation, after the Junos configuration data. For example:

View Metadata Annotations in Configuration Data

The Junos device emits YANG metadata annotations in the Junos configuration within YANG-compliant NETCONF sessions. When you configure NETCONF sessions to be YANG-compliant and retrieve the configuration using the <get-config/> or <get-configuration/> RPC, the device encodes the annotations as per RFC 7952, Defining and Using Metadata with YANG.

To view the configuration with the YANG annotations encoded as per RFC 7952:

  1. Configure the device to enforce YANG-compliant NETCONF sessions.
  2. Retrieve the configuration using the <get-config> or <get-configuration> RPC.
    • Use the NETCONF <get-config> operation to retrieve XML configuration data.

    • Use the Junos XML protocol <get-configuration> operation to retrieve JSON or XML configuration data.

    Note:

    Junos devices only support the openconfig-metadata:protobuf-metadata annotation for JSON encoding. Thus, you can only use the gNMI get() operation or the Junos XML protocol <get-configuration format="json"> RPC to view the annotation in JSON configuration data.