Support for range contexts

Some switch features enable you to use a single command to apply configuration settings to multiple items. You specify the multiple items by creating a type of command context called a range context. Then you can execute commands that are applied to every item in the range. For example:

switch(config)# interface 1/1/1-1/1/5 
switch(config-if-<1/1/1-1/1/5>)# no shutdown

You can use a range context to specify multiple items for the following:

Physical interfaces
  • Command example: interface 1/1/1-1/1/8,1/1/10,1/1/12

  • Switch prompt example: switch(config-if-<1/1/1-1/1/8,1/1/10,1/1/12>)#

VLAN interfaces
  • Command example: interface vlan 1,2,3-6

  • Switch prompt example: switch(config-vlan-if-<1,2,3-6>)#

VLANs
  • Command example: vlan 1-10,15,20-25

  • Switch prompt example: switch(config-vlan-<1-10,15,20-25>)#

Commands entered in a range context are applied to each item in the range individually:

  • Each item in the range has its own entry in the output of show running-config commands.

    For example, you can configure a range of interfaces as follows:

    switch(config)# interface 1/1/1-1/1/5 
    switch(config-if-<1/1/1-1/1/5>)# no shutdown
    

    In the output for the show running-config command, the interfaces are displayed individually:

    switch(config-if-<1/1/1-1/1/5>)# show running-config
    Current configuration:
    ...
    interface 1/1/1
            no shutdown
    interface 1/1/2
            no shutdown
    interface 1/1/3
            no shutdown
    interface 1/1/4
            no shutdown
    interface 1/1/5
            no shutdown
    ...
    switch(config-if-<1/1/1-1/1/5>)#
  • If you specify a range context for interfaces, you cannot execute commands that create a context within the range context. For example, you cannot execute the vrrp command from an interface range context, even though you can execute the command from the config-if context for a single interface.

  • If error is encountered during the execution of a command for an item in the range, the error message returned includes a prefix that identifies the item to which the error applies. However command execution does not stop until the command is attempted on all the items in the range.

  • The range context is created only if every item in the range is successfully created or already exists in configuration. If an error occurs during the creation of an item in a range, the items that are created successfully are added to the configuration, but the range context is not created. The switch prompt.

    For example, in the following sequence:

    1. VLANs 1 through 100 are created successfully, so the switch prompt reflects the range of VLANs: switch(config-vlan-<1-100>)#

    2. The command interface vlan 95-105 fails for VLANs 101 through 105, so the range context is not created and the switch prompt remains in the global configuration context: switch(config)#

    3. The configuration includes all the VLANs and VLAN interfaces that are created successfully.

    switch(config)# vlan 1-100
    switch(config-vlan-<1-100>)# exit
    switch(config)# interface vlan 95-105
    VLAN 101 should be created before creating interface VLAN101.
    VLAN 102 should be created before creating interface VLAN102.
    VLAN 103 should be created before creating interface VLAN103.
    VLAN 104 should be created before creating interface VLAN104.
    VLAN 105 should be created before creating interface VLAN105.
    switch(config)# show running-config
    Current configuration:
    ...
    vlan 1-100
    interface vlan95
    interface vlan96
    interface vlan97
    interface vlan98
    interface vlan99
    interface vlan100
    ...
    switch(config)#
  • If the no form of the command can be used to remove an item from the configuration, you can use a range context with the no form of the command to remove multiple items from the configuration.

    For example, you can remove VLANs 95 through 100 from the configuration by entering: no vlan 95-100