Passing Parameters Through The Macro - Cisco Catalyst 4500 Series Configuration Manual

Release ios xe 3.3.0sg and ios 15.1(1)sg
Hide thumbs Also See for Catalyst 4500 Series:
Table of Contents

Advertisement

Chapter 18
Configuring SmartPort Macros

Passing Parameters Through the Macro

Some commands might not be sufficiently generic for all the interfaces; for example, VLAN ID for
Layer 2 interfaces and the IP address for Layer 3 interface. Retaining such commands in macro
definitions requires that you change the value of such parameters (such as VLAN ID or IP address)
before applying the macro to different interfaces. Alternatively, it requires that you create different
macros for each possible value of its parameters.
The macro infrastructure can be enhanced to support accepting parameters while applying a macro. The
parameters are passed as keyword-value pairs.
The CLI limits the number of keyword-value pairs to a maximum of three, where the first parameter must
be the keyword, the second is its corresponding value, and the third parameter is the keyword for the
second keyword-value pair. Here is an example of how to pass parameters to a command macro:
Switch(config)# macro name parameter-test
Enter macro commands one per line. End with the character '@'.
switchport mode access
switchport access vlan $VLANID
switchport port-security
switchport port-security maximum $MAXHOST
If the above macro is applied to some interface without parameters, the invalid commands fail. Instead,
you should apply the macro with appropriate keyword-value pair parameters, as follows:
Switch(config-if)# macro apply parameter-test $VLANID 1 $MAXHOST 5
The above command applies the macro after replacing $VLANID with 1 and $MAXHOST with 5. Be
aware that you can specify any string in the macro as a keyword.
Macro Parameter Help
It is often difficult to remember the macro keywords while applying a macro to an interface or switch.
Macros can contain the definitions for mandatory keywords. If you apply a macro without those keyword
values, the commands are considered invalid and they fail.
You can enhance the macro infrastructure to provide help on keywords defined in macros. While creating
a macro, you can specify a help string (as a comment) to list the mandatory keywords for that macro.
The following example illustrates how to specify the help string for the keywords:
Switch(config)# macro name test
switchport access vlan $VLANID
switchport port-security maximum $MAX
#macro keywords $VLANID $MAX
Help string can be anywhere in the macro. The following example illustrates an alternate way to specify
the help string:
Switch(config)# macro name test
switchport access vlan $VLANID
#macro keywords $VLANID
switchport port-security maximum $MAX
#macro keywords $MAX
OL-25340-01
Software Configuration Guide—Release IOS XE 3.3.0SG and IOS 15.1(1)SG
Configuring SmartPort Macros
18-3

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents