Macros work by locating apply-macro statements that you include in the candidate configuration and using the values specified in the apply-macro statement as parameters to a set of instructions defined in a commit script. In effect, your custom configuration syntax serves a dual purpose. The syntax allows you to simplify your configuration tasks, and it provides to the script the data necessary to generate a complex configuration.
To enter custom syntax, you include the apply-macro statement at any hierarchy level and specify any data that you want inside the apply-macro statement:
-
apply-macro apply-macro-name {
-
parameter-name parameter-value;
- }
You can include the apply-macro statement at any level of the configuration hierarchy. In this sense, the apply-macro statement is similar to the apply-groups statement. Each apply-macro statement must be uniquely named, relative to other apply-macro statements at the same hierarchy level.
An apply-macro statement can contain a set of parameters with optional values. The corresponding commit script can refer to the macro name, its parameters, or the parameters’ values. When the script inspects the configuration and finds the data, the script performs the actions specified by a persistent or transient change element.
For example, given the following configuration segment, you can write script instructions to generate a standard configuration based on the name of the parameter:
protocols {
mpls {
apply-macro blue-type-lsp {
color blue;
}
}
}
The following <xsl:for-each> programming instruction finds apply-macro statements at the [edit protocols mpls] hierarchy level that contain a parameter named color:
- <xsl:for-each select="protocols/mpls/apply-macro[data/name
= 'color']">
The following instruction creates a variable named color and assigns to the variable the value of the color parameter, which in this case is blue:
- <xsl:variable name="color" select="data[name = 'color']/value"/>
The following instruction adds the admin-groups statement to the configuration and assigns the value of the $color variable to the group name:
<transient-change>
<protocols>
<mpls>
<admin-groups>
<name>
<xsl:value-of select="$color"/>
</name>
</admin-groups>
</mpls>
</protocols>
</transient-change>
The resulting configuration statements are as follows:
protocols {
mpls {
admin-groups {
blue;
}
}
}