Creating a Smartport Macro
Smartport macros are a great time saving tool for you to use to help with your Cisco network switch configurations. To make them even more powerful, you can create your own macros from scratch.
Before boring you with Cisco’s rules though, you should note the following things about macros:
When a macro is applied to an interface, all existing configuration on the interface is retained. This is not a total replacement of the configuration, but an augmentation to the existing configuration.
A macro can contain up to 3,000 characters of text. This is not as limiting as a tweet, say, but it does mean that you need to pay attention to what you want to accomplish and get to the point with your macro.
Macros are case-sensitive, so watch your use of case in the macro name. For example, MyMacro is not the same macro as Mymacro or mymacro, all of which could perform completely different operations.
You have a lot of latitude when using Smartport macros, but here are a few Do not’s!
You are not allowed to use exit or end, which would exit you from Interface Configuration mode or Global Configuration mode. The macro needs to run in the context of one interface.
Similar to the previous rule, you are not allowed to change the command mode with a command such as the interface command. All commands for a macro need to execute in the current command mode.
To create a macro, you need to enter the Macro Editor mode using the macro name command.
When you want to complete your macro, end it with an @ symbol.
You use the # sign to issue a comment line within a macro. Use comment lines to identify the purpose of your macro statements.
Smartport macros and parameters
When working with Smartport macros, you have the option of creating parameters to use within the macros. You identify these parameters in the macro by using the macro keywords directive in your macro.
When you run this macro you will use the macro apply command to provide the macro your parameters. By using parameters, you can make your macros much more flexible and useful.
Creating a sample macro
You are now ready to create a macro; for this example the Awesome_Macro was created. This macro uses parameters and assigns some of the settings that are applied with the cisco-desktop macro..
Switch1> enable Switch1# configure terminal Switch1(config)# macro name Awesome_Macro Enter macro commands one per line. End with the character '@'. # macro keywords $VLAN_ID # Basic interface - Enable data VLAN only # Recommended value for VLAN_ID should not be 1 switchport access vlan $VLAN_ID switchport mode access # Configure port as an edge network port spanning-tree bpduguard enable @ Switch1(config)#exit Switch1#show parser macro name Awesome_Macro Macro name : Awesome_Macro Macro type : customizable # macro keywords $VLAN_ID # Basic interface - Enable data VLAN only # Recommended value for VLAN_ID should not be 1 switchport access vlan $VLAN_ID switchport mode access # Configure port as an edge network port spanning-tree bpduguard enable
After creating the Smartport macro, use the show command to verify that the macro was typed correctly.