Deploy-time references in leaf values

A leaf value of a yang::NetconfResource, yang::GnmiResource or yang::RestconfResource can be a reference, for example a secret, an environment variable or a fact. The reference is resolved by the agent right before the resource is deployed (or dry-run), so its value doesn’t have to be known at compile time.

How it works

  • yang::NetconfResource: the exported xml holds a placeholder (@REF:<n>@) for each leaf whose value is a reference. The xml attribute of the resource is then a yang::XmlReference, which wraps this xml template and the leaf references. Before the handler runs, the agent resolves the leaf references, writes their values in the template and sets the result as xml of the resource (core::Replace mutator).

  • yang::RestconfResource: the same, for the xml value of each edit of the set_request.

  • yang::GnmiResource: the reference is kept in the json value of the set_request, the agent replaces it by its value.

Setting a reference on a leaf

Set the reference as value (or in wrapped_value) of a leaf yang::Container, or as a non-key value in subs. Assign the description of a Nokia SR OS loopback from an environment variable on the agent:

import yang
import std

interface = yang::Container(
    name="interface",
    parent=router,
    subs={"interface-name": "system-lo", "admin-state": "enable"},
    key_attribute=["interface-name"],
)
yang::Container(
    name="description",
    parent=interface,
    value=std::create_environment_reference("LOOPBACK_DESCRIPTION"),
    is_actual=false,
)

The same leaf, from subs:

interface = yang::Container(
    name="interface",
    parent=router,
    subs={
        "interface-name": "system-lo",
        "admin-state": "enable",
        "description": std::create_environment_reference("LOOPBACK_DESCRIPTION"),
    },
    key_attribute=["interface-name"],
)

Leaf-list items in subs can be references as well.

Value of a reference

The reference must resolve to the leaf value: a string, a number or a boolean. Attributes using a constrained type (e.g. yang::types::uint32) don’t accept a reference, use value (a string) or subs instead. The device rejects invalid values on deploy.

To check the value, or to derive it from another reference (e.g. the values of a verification result published by a yang::NetconfVerify, see Referencing a verified result), wrap it in a module-specific reference.

Limitations

  • References are not supported in key leaves (they identify the list entry), or in identityref leaves.

  • For a yang::GnmiResource, a leaf with another operation than its parent is the whole value of a gnmi update, it can not be a reference.

  • A reference resolving to None fails the deploy: purge or leave out the leaf instead.

  • Resolved values are not masked: they show up in the handler logs (the configuration applied on the device) and in dry-run diffs, which are stored on the server.

  • For yang::NetconfResource and yang::RestconfResource, leaf texts matching the placeholder format (@REF:<n>@) are reserved, such a static value fails the deploy.