0 Replies Latest reply on May 22, 2018 1:16 PM by cslacker

    Possible to iterate through all interfaces without declaring in template?

    cslacker

      Is it possible to iterate through all interfaces on a device without specifying them in "Define Variables"?  The script below is meant to ask the user for a VRF name, then ask what ip addresses to place into the VRF.  I achieve this by matching the IPAddress.InterfaceIndex to the Interface.InterfaceIndex to know which interface to apply the config against.  I don't really need the user to specify which interfaces to inspect.

       

      If there's a better way to do this I'm happy to hear it!

       

       

       

      /*

      .CHANGE_TEMPLATE_DESCRIPTION

              This template configures physical interfaces based on interface description.  It was verified on a Cisco 2950 Catalyst Switch running IOS software version 12.1(12c).

      .CHANGE_TEMPLATE_TAGS

          Cisco, interface, VLAN, description, properties

      .PLATFORM_DESCRIPTION

              Cisco IOS

       

      .PARAMETER_LABEL @ContextNode

              NCM Node

      .PARAMETER_DESCRIPTION @ContextNode

              The node the template will operate on.  All templates require this by default. The target node is selected during the first part of the wizard so it will not be available for selection when defining values of variables.

       

      .PARAMETER_LABEL @VRFName

              VRF names

      .PARAMETER_DESCRIPTION @VRFName

              Enter a VRF name that you would like on the device(s.

       

      .PARAMETER_LABEL @PlaceInVRF

              IP Addresses to place

      .PARAMETER_DESCRIPTION @PlaceInVRF

              Select IP addresses you'd like to plop into this VRF.

       

      */

       

      script ChangeInterfacesBasedOnDescription (

                                                  NCM.Nodes @ContextNode,

                                                  string @VRFName, 

                                                  NCM.Interfaces[] @AllPorts,

                                                  NCM.IpAddresses[] @PlaceInVRF

                                                )

      {

        // Enter configuration mode

        CLI

        {

          configure terminal

          ip vrf @VRFName

        }

        foreach (@IP in @PlaceInVRF)

        {

          foreach (@Port in @AllPorts)

          {

            if (@IP.InterfaceIndex == @Port.InterfaceIndex)

            {

              CLI

              {

                int @Port.InterfaceName

                ip vrf forwarding @VRFName

                ip address @IP.IPAddress @IP.SubnetMask

                exit

              }

            }

          }

        }

        CLI

        {

          end

        }

      }

      }