Schema inspection

Connection.get_schema(path)

Return the schema meta-data for a path.

This method returns a SchemaClass describing the last element of the path:

>>> schema = conn.get_schema(RootCfg.InterfaceConfiguration)
>>> print(schema)
SchemaClass(InterfaceConfiguration)
>>> schema.description
'The configuration for an interface'
>>> for child in schema.children[:5]:
...     print(child)
Path(RootCfg.InterfaceConfiguration.PseudowireEther)
Path(RootCfg.InterfaceConfiguration.IPv6Neighbor)
Path(RootCfg.InterfaceConfiguration.MACAccounting)
Path(RootCfg.InterfaceConfiguration.IPV6PacketFilter)
Path(RootCfg.InterfaceConfiguration.PTP)

The input Path identifies the point of interest in the schema hierarchy.

Any key values in the path are ignored. In particular, it’s ok to omit key values even where they’d usually be mandatory:

>>> cls = conn.get_schema(RootCfg.InterfaceConfiguration.VRF)
>>> print(cls)
SchemaClass(VRF)

If the path doesn’t identify a valid sequence of classes in the schema, PathHierarchyError is raised:

>>> conn.get_schema(RootOper.Missing.Interface)
PathHierarchyError: 'Missing' is not a child of 'RootOper'
Parameters:

pathPath identifying the point in the hierarchy of interest.

Returns:

A SchemaClass object, as above.

Raises:

Hierarchy

class xrm2m.SchemaClass

Meta-data for a node in the schema hierarchy.

Schema classes describe a type of management data that may exist and the properties of any such data.

For example:

# To navigate to a particular point in the schema, create a Path
# without filling in key values.
>>> path = RootCfg.InterfaceConfiguration.VRF
>>> cls_info = conn.get_schema(path)
>>> cls_info.name
'VRF'
>>> cls_info.category
<SchemaClassCategory.LEAF: 2>
>>> cls_info.description
'Assign the interface to a VRF'
>>> for param in cls_info.value()
...     print(param)
SchemaParam(BoundedString(1, 32) VRFName)
name

Name of this class in the schema.

category

Category of this class.

A class’ category denotes what data it describes e.g. whether it’s a container for other classes, or has an associated value.

description

String giving a verbose description of the semantics of data described by the class.

table_description

Same as description, for the table described by this class, if any.

key

Data type information for this class’ key parameters. This is a list of SchemaParam objects, each describing a single key parameter.

The ‘key’ of a class is the collection of parameters whose values distinguish different instances of the class in data described by the schema. This attribute describes the format and meaning of those values. For example:

>>> print(route_cls)
SchemaClass(IP_RIBRoute)
>>> for param in route_cls.key():
...     print(param)
SchemaParam(String RouteTableName)
value

Data type information for this class’ value parameters. This is a list of SchemaParam objects, each describing a single value parameters.

This attribute describes the format and meaning of the data contained in instances of this class. An example from the BGP config schema:

>>> print(bufsizes)
SchemaClass(ReceiveSocketBufferSizes)
>>> for param in bufsizes.value():
...     print(param)
SchemaParam(Range(512, 13107) SocketReceiveSize)
SchemaParam(Range(512, 13107) BGPReceiveSize)

Note that if the leaf represents a bag, then value will be a singleton list containing a SchemaParam of type Datatype.BAG.

Note that if the leaf represents a bag, then value will be a singleton list containing a SchemaParam of type Datatype.BAG.

presence

A Path identifying the leaf class that gives this class ‘presence’, or None if there is no such leaf class.

Container classes may have a nominated leaf class that defines whether the container exists or not, a similar concept to ‘containers with presence’ in YANG. This method returns a path to the nominated class, if any.

version

Current Version of this class or UNVERSIONED if this class has the same version as its parent.

For example:

>>> print(cls)
SchemaClass(InterfaceProperties)
>>> cls.version()
Version(major=3, minor=2)
table_version

Same as version, for the table described by this class, if any. None if the class does not describe a table.

hidden

True if this class is hidden, False otherwise.

Classes are typically hidden to mark them as deprecated. See version_compatibility.

version_compatibility

Minimum and maximum schema versions this class is compatible with.

This is a (min version, max version) tuple of Version instances. It can be used to determine whether a class is deprecated (in which case it’s also likely to be marked as hidden):

>>> print(cls)
SchemaClass(DefaultVRF)
>>> current = cls.version()
>>> min_supported, max_supported = cls.version_compatibility()
>>> max_supported < current
True
>>> current
Version(major=10, minor=0)
>>> max_supported
Version(major=8, minor=0)
>>> cls.hidden()
True

A deprecated class is still a valid representation of management data, but represents an outdated or incomplete view of that data.

If a class is compatible with known versions after a certain point, the MAX_VERSION singleton is used to represent the maximum compatible version:

>>> print(cls)
SchemaClass(Node)
>>> cls.version_compatibility()
(Version(major=2, minor=0), MAX_VERSION)
>>> Version(major=100, minor=20) < MAX_VERSION
True

If a class contains no compatibility information, then UNVERSIONED is returned for both the min and max versions.

table_version_compatibility

Same as :attr:’version_compatibility`, for the table described by this class, if any. None if the class does not describe a table.

children

List of paths to children of this class in the schema:

>>> cls = conn.get_schema(RootCfg.InterfaceConfiguration)
>>> for child in cls.children[:5]:
...     print(child)
Path(RootCfg.InterfaceConfiguration.PseudowireEther)
Path(RootCfg.InterfaceConfiguration.IPv6Neighbor)
Path(RootCfg.InterfaceConfiguration.MACAccounting)
Path(RootCfg.InterfaceConfiguration.IPV6PacketFilter)
Path(RootCfg.InterfaceConfiguration.PTP)
bag_types

Bag types relevant to this schema node, or None if value does not contain (a single) SchemaParam of type Datatype.BAG.

bag_types contains schema information for structures (equivalently bags), unions, and enums that are directly or indirectly referenced by this node’s schema parameter. It is structured as a dict in the following form:

>>> schema_info = conn.get_schema(intf_config))
>>> pprint(schema_info.bag_types)
{
    'im_if_type_summary_st': BagType(
        name='im_if_type_summary_st',
        description='', datatype=<BagDatatype.STRUCT: 2>,
        children=[
             string InterfaceTypeName,
             string InterfaceTypeDescription,
             struct im_if_group_counts_st InterfaceCounts
        ],
        datatype_args=None
    ),
    'im_if_group_counts_st': BagType(
        name='im_if_group_counts_st',
        description='',
        datatype=<Datatype.STRUCT: 2>,
        children=[
            uint32 InterfaceCount,
            uint32 UpInterfaceCount,
            uint32 DownInterfaceCount,
            uint32 AdminDownInterfaceCount
        ],
        datatype_args=None
    ),
    'im_if_summary_info': BagType(
        name='im_if_summary_info',
        description='Interface summary bag',
        datatype=<Datatype.STRUCT: 2>,
        children=[
            struct im_if_type_summary_st InterfaceTypeList[],
            struct im_if_group_counts_st InterfaceCounts
        ],
        datatype_args=None
    )
}

Keys of the dict correspond with this node’s schema parameter’s name field:

In the case that the bag corresponding with this node contains a structure, enum, or union as one of its parameters, then the structure, enum, or union is referenced by the datatype_name attribute of the corresponding BagParam. For example, if the third bag parameter is a struct, and the fourth a union:

Such nested structs and unions may themselves refer to further nested structs, unions and enums in a similar way.

class xrm2m.SchemaClassCategory

Enumeration of classifications of schema classes.

CONTAINER

Denotes a class that acts as a container for other classes (its children) and has no value.

LEAF

Denotes a class whose instances have a value. Leaf classes have no child classes.

class xrm2m.Version

Named tuple describing the version of an object in the schema.

If version information is requested for an object that’s not versioned, the UNVERSIONED singleton is returned rather than an instance of this class.

The MAX_VERSION singleton represents an ‘infinitely high’ version.

major

Major version number.

minor

Minor version number.

xrm2m.MAX_VERSION

Singleton representing an arbitrarily high Version, i.e. this is greater than every other version.

xrm2m.UNVERSIONED

Singleton representing absence of version information.

Bags

class xrm2m.BagType

Typing information for a composite type.

A composite type is either a structure, an enumeration, or a union.

name

Brief string description of the meaning of data described by this type, e.g. “Bandwidth”.

description

Verbose string description of the meaning of data described by this type, e.g. “Interface bandwidth (Kb/s)”.

datatype

A instance of BagDatatype, indicating whether the type being described is a structure, union or enumeration. (Ie. datatype.is_composite() will always be true.)

children

Describes the subelements of this structure, union or enumeration.

If datatype is BagDatatype.STRUCT or .BagDatatype.UNION, then this attribute is a list of instances of BagParam.

If datatype is BagDatatype.ENUM, then this attribute is a list of instances of BagEnumElement.

datatype_args

Additional information for a particular datatype. Specifically, if the datatype is BagDatatype.UNION, this is an instance of :class:.`BagUnionArgs`.

class xrm2m.BagParam

Typing information for a single item of data in a bag.

In particular, this describes an element in a structure or union, or a union discriminator.

name

Brief string description of the meaning of data described by this parameter, e.g. ‘Bandwidth’ for a parameter describing an interface’s configured bandwidth value.

description

Verbose string description of the meaning of data described by this parameter, e.g. ‘Bandwidth of the interface in kbps’ for a bandwidth parameter.

datatype

Element of BagDatatype.

datatype_name

If the datatype is a composite datatype, this is the name of the type, which can be used as the key into the types dictionary to find detailed type information. Otherwise, this is None.

BagDatatype.is_composite() can be used to determine if a datatype is composite or not.

status

Element of BagParamStatus describing requirements on values described by this parameter e.g. whether specifying the value is optional.

status_args

Additional information on the node based on the status.

If the status is BagParamStatus.LIST, this is an list of instances of BagListArgs, describing the list entries.

Otherwise it is None.

class xrm2m.BagParamStatus

Enumeration of schema parameter statuses.

MANDATORY

Value must be specified for this parameter.

OPTIONAL

Value may be specified for this parameter.

LIST

Value is a list of parameters of the given type.

class xrm2m.BagUnionArgs

Additional information for union types defined in bags.

discriminator

An instance of BagParam describing the discriminator for the union. This is a parameter with datatype ENUM whose value determines which entry of the union is selected.

default

The identifier of the discriminator enumeration value to be used by default to determine the case.

class xrm2m.BagEnumElement

Typing information for an enumeration value in a bag.

name

Brief string description of the meaning of data described by this parameter, e.g. ‘Enabled’ for a value representing the fact that an interface is enabled.

description

Verbose string description of the meaning of data described by this parameter, e.g. ‘The interface is enabled’ for the example above.

class xrm2m.BagListArgs

Additional information for instances of BagParam with a status of BagParamStatus.LIST.

fixed_length

Set to true to indicate that the list in question has a fixed length (given by the max_length attribute), or false if it the length is variable.

max_length

If fixed_length is true, this is an integer value indicating the length of the list. Otherwise, this may be an integer value denoting the upper bound of the list length, or None if there is no upper bound.

Typing

Parameters

class xrm2m.SchemaParam

Typing information for a single key or value parameter.

datatype

Element of Datatype.

name

Brief string description of the meaning of data described by this parameter, e.g. ‘Bandwidth’ for a parameter describing an interface’s configured bandwidth value.

description

Verbose string description of the meaning of data described by this parameter, e.g. ‘Bandwidth of the interface in kbps’ for a bandwidth parameter.

datatype_args

If datatype is a parameterised type, a dict containing the parameter values for this instance of the type. For unparameterised types, this is None.

For integer range types:

>>> param
SchemaParam(Range(5, 16) MaxRecursionDepth)
>>> param.description
'Maximum depth for route recursion check'
>>> pprint(param.datatype_args)
{
    "min": 5,
    "max": 16,
}

For restricted-length string types:

>>> param
SchemaParam(BoundedString(0, 244) Description)
>>> param.description
'VRF description'
>>> pprint(param.datatype_args)
{
    "minlen": 0,
    "maxlen": 244,
}

For instances of the enum type:

>>> param
SchemaParam(Enum Mode)
>>> pprint(param.datatype_args)
{
    "Default": {
        "value": 0,
        "description": "Default interface mode",
    },
    "PointToPoint": {
        "value": 1,
        "description": "Point-to-point interface mode",
    },
    "Multipoint": {
        "value": 2,
        "description": "Multipoint interface mode",
    },
    "L2Transport": {
        "value": 3,
        "description": "L2 transport interface mode",
    },
}

For instances of the range enum type:

>>> param
SchemaParam(RangeEnum(0, 4294967295) MeshGroup)
>>> pprint(param.datatype_args)
{
    "min": 0,
    "max": 4294967295,
    "enum": {
        "Blocked": {
            "value": 0,
            "description": "Blocked mesh group. Changed LSPs are "
                           "not flooded over blocked interfaces",
        },
    },
}

For instances of the string list type:

>>> param
SchemaParam(StringList Active)
>>> pprint(param.datatype_args)
{
    "act": {
        "description": "Interface is active",
    },
    "pre": {
        "description": "Interface is preconfigured",
    },
}
repeat_count

Number of times this parameter is repeated in data described by the schema. This is 1 unless this parameter is an array.

status

Element of SchemaParamStatus describing requirements on values described by this parameter e.g. whether specifying the value is optional.

internal_name

Name used to refer to this parameter internally within the IOS-XR system. It is set only if this data is of type BAG. Otherwise it is None.

If set it is usually the same as name.

This information is intended for use by IOS-XR tools built on top of MPG. It’s unlikely to be useful in other scenarios.

class xrm2m.SchemaParamStatus

Enumeration of schema parameter statuses.

MANDATORY

Value must be specified for this parameter.

OPTIONAL

Value may be specified for this parameter.

IGNORED

Value may be specified for this parameter, but any value given will have no effect on the system.

This status is typically used to denote a parameter that no longer has a meaning after an update to the schema, while preserving backwards compatibility.

Data types

class xrm2m.Datatype

Enumeration of datatypes that appear in the schema.

INTEGER

Unsigned 32-bit integer

HEX_INTEGER

Unsigned 32-bit integer

SIGNED_INTEGER

Signed 32-bit integer

BOOL

Boolean

TRUE_ONLY

Boolean restricted to True

FALSE_ONLY

Boolean restricted to False

RANGE

Unsigned 32-bit integer range

SIGNED_RANGE

Signed 32-bit integer range

ENUM

Integer-valued enum

RANGE_ENUM

Unsigned 32-bit integer range with labels

STRING

ASCII-compatible string

TEXT

ASCII-compatible string

IDENTIFIER

Identifier string

ENCODED_STRING

ASCII-compatible string

BOUNDED_STRING

Restricted-length ASCII-compatible string

BOUNDED_IDENTIFIER

Restricted-length identifier string

ENCODED_BOUNDED_STRING

Restricted-length ASCII-compatible string

STRING_LIST

String-valued enum

BAG

Composite data

IPV4ADDRESS

IPv4 address

MASK

IPv4 address

IPV4ADDRESS_STRING

IPv4 address

IPV4HOSTNAME

IPv4 address

IPV6ADDRESS

IPv6 address

IPV6ADDRESS_PLUS

IPv6 address

IPV6ADDRESS_STRING

IPv6 address

IPV6ADDRESS_HEXSTRING

IPv6 address

IPV6HOSTNAME

IPv6 address

IPADDRESS

IP address

IPADDRESS_STRING

IP address

IPHOSTNAME

IP address

IPADDRESS_PREFIX

IP address and prefix length

VRF

VRF

MACADDRESS

MAC address

MACADDRESS_STRING

MAC address

INTERFACE_NAME

Interface name

INTERFACE_HANDLE

Interface name

INTERFACE_FORWARD

Interface name

NODEID

Node ID

SYSDB_NODEID

Node ID

NODEID_STRING

Node ID

PHYSICAL_NODEID

Node ID

PHYSICAL_NODEID_STRING

Node ID

EXTENDED_NODEID

Node ID

PQ_NODEID

Partially-qualified node ID

PQ_NODEID_STRING

Partially-qualified node ID

RACKID

Rack ID

ENCRYPTION_TYPE

Enum of cryptographic algorithms

ENCRYPTED_STRING

Obfuscated string

ENCRYPTION_STRING

Obfuscated string

MD5_PASSWORD

Obfuscated string

PROPRIETARY_PASSWORD

Obfuscated string

OSI_SYSTEMID

OSI system ID

OSI_AREA_ADDRESS

OSI area address

ISIS_NODEID

IS-IS node ID

ISIS_LSPID

IS-IS LSP ID

OSI_NET

OSI NET

CHARNUM

Byte value

TTY_ESCAPE_CHARNUM

Byte value or special value

TTY_ESCAPE_CHARNUM

Byte value or special value

class xrm2m.BagDatatype

Enumeration of datatypes used for bag nodes.

NONE

No data.

INT8

8-bit signed integer.

UINT8

8-bit unsigned integer.

INT16

16-bit signed integer.

UINT16

16-bit unsigned integer.

INT32

32-bit signed integer.

UINT32

32-bit unsigned integer.

INT64

64-bit signed integer.

UINT64

64-bit unsigned integer.

IPV4_ADDRESS

IPv4 address.

ENUM

Enumeration.

BOOL

Boolean (true or false).

VOID

Void value.

STRING

ASCII string.

OPAQUE

Binary data.

IPV4_TUNNEL_ADDRESS

IPv4 tunnel address.

IPV4_MDT_ADDRESS

IPv4 MDT address.

RT_CONSTRAINT_ADDRESS

RT constraint address.

IPV4_MVPN_ADDRESS

IPv4 MVPN address.

IPV6_MVPN_ADDRESS

IPv6 MVPN address.

IP_L2VPN_EVPN_ADDRESS

IP L2VPN EVPN address.

IP_L2VPN_MSPW_ADDRESS

IP L2VPN MSPW address.

LINKSTATE_ADDRESS

Linkstate address.

IPV4_FlOWSPEC_ADDRESS

IPv4 flowspec address.

IPV6_FLOWSPEC_ADDRESS

IPv6 flowspec address.

IPV6_ADDRESS

IPv6 address.

MAC_ADDRESS

MAC address.

HEXINTEGERTYPE

Hexadecimal integer.

NODEID

Node identifier.

IFHTYPE

Interface handle.

HEX_BINARY

Hexadecimal binary data.

INLINE_STRING

Inline string.

OSI_SYSTEMID

OSI system identifier.

OSI_AREAADDRESS

OSI area address

ISIS_NODEID

ISIS node ID.

ISIS_LSPID

ISIS LSP ID.

INTERFACE_CAPS

Interface capsulation ID.

INTERFACE_PROTO

Interface protocol ID.

INTERFACE_TYPE

Interface type.

ROUTE_DISTINGUISHER

Route distinguisher.

VRF_ID

VRF ID.

STRUCT

Denotes a type that acts as a container for other types (its children).

UNION

Denotes a type with a set of children, only one of which may be active at any given time.

ENUM

Denotes an enumeration type; its children are the possible values a node of this type may take.

Parameterised types

Certain data types have associated parameters: for example, every instance of the RANGE type has two associated integer arguments giving the min and max values for the range:

>>> param
SchemaParam(Range(5, 16) MaxRecursionDepth)
>>> param.datatype
<Datatype.RANGE: 'Range'>
>>> param.datatype_args
{'min': 5, 'max': 16}

The following table lists all of the parameterised types (see also SchemaParam.datatype_args):

Data type classification Data types
Integer range types RANGE
SIGNED_RANGE
Restricted-length string types BOUNDED_STRING
BOUNDED_IDENTIFIER
ENCODED_BOUNDED_STRING
Enum type ENUM
Range enum type RANGE_ENUM
String list type STRING_LIST