Quantcast
Channel: THWACK: All Content - Network Configuration Manager
Viewing all articles
Browse latest Browse all 6057

Iterate through Router Interfaces and Conditionally Add a Config Statement

$
0
0

Folks,

 

What I'm doing to achieve is for the script to detect that there is a Loopback1 on a Cisco router interface and give it a description.  This is what I have so far:

 

/*

.CHANGE_TEMPLATE_DESCRIPTION

        Add multicast configuration statements to WAN routers

.CHANGE_TEMPLATE_TAGS

        Cisco, IOS, Router, Multicast

.PLATFORM_DESCRIPTION

        Cisco IOS

.PARAMETER_LABEL @ContextNode

        NCM Node

.PARAMETER_DESCRIPTION @ContextNode

        The NCM nodes the template will operate on. Target nodes are selected during the first part of the wizard and cannot be changed when defining values of variables.

*/

 

script ChangeInterfacesBasedOnDescription (

                                            NCM.Nodes @ContextNode )

 

{

  // Enter configuration mode

  CLI

  {

    configure terminal

  }

 

  // Loop through selected interfaces

  foreach (@interfaceItem in @ContextNode.Interfaces)

  {

    if (@interfaceItem.InterfaceDescription contains 'Loopback1')

    {

     //Go into Interface Configuration Mode

      interface @interfaceItem.InterfaceDescription

 

      // configure the Interface

      description For Telco A

      exit

    }

  }

 

  // Exit configuration mode

  CLI

  {

    exit

    write mem

  }

}

 

When looking at the results of the script, the device is not getting into interface configuration mode:

 

configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
end
write mem
Building configuration...
[OK]

 

So what I don't understand is:

- What is InterfaceDescription versus InterfaceName?  The Administrator Guide isn't exactly clear.

- is the reference to the interface enough or do I need to store it in a variable before using it?

- Clearly I'm doing something wrong but I haven't figured out what it is yet.  Any observations or clues?

- If I was writing a Perl script I'd be able to place a print statement to STDOUT to tell me what the value of @interfaceItem is.  is there something similar with this scripting tool?

 

Thank you for your help.

 

Timothy


Viewing all articles
Browse latest Browse all 6057

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>