Quantcast
Channel: THWACK: Message List - Network Configuration Manager
Viewing all articles
Browse latest Browse all 8827

NCM Scripting Questions - Goto End ? IF & OR statements ?

$
0
0

Hi All,

   looking for some clarification from one of the experts regarding scripting in NCM please.  I've written a script to identify interfaces that have a specific description and perform a given command.  The problem is, that the specific description has a few iterations, depending on who configured it, which is frustrating of course (it should be standard).

 

My first question is, can someone give me a recommendation on simplifying the if statement matching ?  I.E. rather than multiple "if" matches, is there a possibility to use an "or" syntax somewhere to just create one statement ?  something like

 

  if (@interfaceItem.InterfaceAlias contains 'aaa' or 'bbb' or 'ccc' or 'ddd' or 'eee' or 'fff')  ?

 

My second question, if this can not be achieved, is there a way to skip to the end if a match is found ?  using an @endscript variable or the like ? what is the syntax for this ?

 

/*

.CHANGE_TEMPLATE_DESCRIPTION

        This template configures physical interfaces based on interface description

.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.

 

 

*/

 

 

script ChangeInterfacesBasedOnDescription ( NCM.Nodes @ContextNode )

{

  int @MatchFound

  

  @MatchFound = 0

 

  // Loop through selected interfaces

  foreach (@interfaceItem in @ContextNode.Interfaces)

  {

    if (@interfaceItem.InterfaceAlias contains 'aaa')

    {

             // Set command

             CLI

             {

                configure terminal

                interface @interfaceItem.InterfaceDescription

                no cdp enable

             }

             @MatchFound = 1

     }

    if (@interfaceItem.InterfaceAlias contains 'bbb')

    {

             // Set command

             CLI

             {

                configure terminal

                interface @interfaceItem.InterfaceDescription

                no cdp enable

             }

             @MatchFound = 1

     }

    if (@interfaceItem.InterfaceAlias contains 'ccc')

    {

             // Set command

             CLI

             {

                configure terminal

                interface @interfaceItem.InterfaceDescription

                no cdp enable

             }

             @MatchFound = 1

     }

    if (@interfaceItem.InterfaceAlias contains 'ddd')

    {

             // Set command

             CLI

             {

                configure terminal

                interface @interfaceItem.InterfaceDescription

                no cdp enable

             }

             @MatchFound = 1

     }

    if (@interfaceItem.InterfaceAlias contains 'eee')

    {

             // Set command

             CLI

             {

                configure terminal

                interface @interfaceItem.InterfaceDescription

                no cdp enable

             }

             @MatchFound = 1

     }

    if (@interfaceItem.InterfaceAlias contains 'fff')

    {

             // Set command

             CLI

             {

                configure terminal

                interface @interfaceItem.InterfaceDescription

                no cdp enable

             }

             @MatchFound = 1

     }

    }

  // Exit configuration mode

  CLI

  {

    exit

  }

  if (@MatchFound != 1)

  {

     CLI

     {

         ### NO MATCHES FOUND ###

     }

  }

}


Viewing all articles
Browse latest Browse all 8827

Trending Articles



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