Request Subsets of Configuration Objects Using Regular Expressions
In a Junos XML protocol session with a device running Junos
OS, to request information about only those instances of a configuration
object type that have a specified set of characters in their identifier
names, a client application includes the matching
attribute with a regular expression that matches the identifier
name. For example, the application can request information about just
the SONET/SDH interfaces at the [edit interfaces]
hierarchy
level by specifying the characters so- at the start of the regular
expression.
Using the matching
attribute
enables the application to represent the objects to return in a form
similar to the XML Path Language (XPath) representation, which is
described in XML Path Language (XPath) Version 1.0, available from the World Wide Web Consortium (W3C) at http://www.w3.org/TR/xpath . In an XPath representation, an object and its parent levels are
an ordered series of tag element names separated by forward slashes.
The angle brackets around tag element names are omitted, and the opening
tag is used to represent the entire tag element. For example, the
following XPath:
configuration/system/radius-server/name
is equivalent to the following tagged representation:
<configuration> <system> <radius-server> <name/> </radius-server> </system> </configuration>
The application includes the matching
attribute in the empty tag that represents a parent level for the
object type. As with all requests for configuration information, the
client emits a <get-configuration>
tag
element that encloses the tag elements representing all levels of
the configuration hierarchy from the root (represented by the <configuration>
tag element) down to the level at
which the matching
attribute is included.
The entire request is enclosed in an <rpc>
tag element:
<rpc> <get-configuration> <configuration> <!-- opening tags for each parent of the level --> <level matching="matching-expression"/> <!-- closing tags for each parent of the level --> </configuration> </get-configuration> </rpc>
In the value for the matching
attribute,
each level in the XPath-like representation can be either a full level
name or a regular expression that matches the identifier name of one
or more instances of an object type:
object-type[name='regular-expression']"
The regular expression uses the notation defined in POSIX Standard 1003.2 for extended (modern) UNIX regular expressions. Explaining regular expression syntax is beyond the scope of this document, but Table 1 specifies which character or characters are matched by some of the regular expression operators that can be used in the expression. In the descriptions, the term term refers to either a single alphanumeric character or a set of characters enclosed in square brackets, parentheses, or braces.
The matching
attribute is not
case-sensitive.
Operator |
Matches |
---|---|
|
One instance of any character except the space. |
|
Zero or more instances of the immediately preceding term. |
|
One or more instances of the immediately preceding term. |
|
Zero or one instance of the immediately preceding term. |
|
One of the terms that appear on either side of the pipe operator. |
|
The start of a line, when the caret appears outside square brackets. One instance of any character that does not follow it within square brackets, when the caret is the first character inside square brackets. |
|
The end of a line. |
|
One instance of one of the enclosed alphanumeric characters.
To indicate a range of characters, use a hyphen (-) to separate the
beginning and ending characters of the range. For example, |
|
One instance of the evaluated value of the enclosed term. Parentheses are used to indicate the order of evaluation in the regular expression. |
When the application requests Junos XML-tagged output
(the default), the Junos XML protocol server returns the requested
object in <configuration>
and <rpc-reply>
tag elements. For information about
the attributes in the opening <configuration>
tag, see Specifying the Source for Configuration
Information Requests in a Junos XML Protocol Session.
<rpc-reply xmlns:junos="URL"> <configuration attributes> <!-- opening tags for each parent of the parent level --> <parent-level> <first-matching-object> <!-- child tag elements for the first object --> </first-matching-object> <second-matching-object> <!-- child tag elements for the second object --> </second-matching-object> <!-- additional instances of the object --> </parent-level> <!-- closing tags for each parent of the object type --> </configuration> </rpc-reply>
The application can combine one or more of the count
, start
, and recurse
attributes along with the matching
attribute, to limit the set of possible matches to a specific range
of objects, to request only identifiers, or both. For more information
about those attributes, see Requesting
a Specific Number of Configuration Objects Using the Junos XML Protocol and Requesting Identifiers for Configuration
Objects of a Specific Type Using the Junos XML Protocol.
To specify the source of the output (candidate or active configuration)
and request special formatting of the output (for example, formatted
ASCII or JSON or an indicator for identifiers), the application can
include attributes in the opening <get-configuration>
tag, its opening <junoscript>
tag,
or both. For more information, see Specifying
the Source for Configuration Information Requests in a Junos XML Protocol
Session and Specifying the
Output Format for Configuration Data in a Junos XML Protocol Session.
The application can request additional configuration elements
of the same or other types in the same <get-configuration>
tag element by including the appropriate tag elements. For more
information, see Requesting Multiple Configuration
Elements Using the Junos XML Protocol.
The following example shows how to request just the identifier
for the first two SONET/SDH interfaces configured at the [edit interfaces]
hierarchy level.