Quantcast
Channel: THWACK: All Content - All Communities
Viewing all articles
Browse latest Browse all 20202

Using Config Change Script to Identify Switch Interface Mode

$
0
0

Hello Everyone,

I recently found out about the Config Change Scripts, and it is magnificent. I started using the (out-of-the-box) ones and tweaking them. Then started to write some for my own and testing them on the LAB setup that we have. However, I hit a wall when I could not identify a Cisco switch port if it is in Access mode or in Trunk mode.

The scenario I have is that there are many switches and I need to enable (bpduguard) and (root guard) on the switches' access ports. But in order to that, I have to identify the switch mode (Acces / Trunk) and I could not figure it out from NCM Admin guide.

If anyone has tried it or know about this, it would be great to help.

I use NCM 7.0.2

 

BTW, here is a script I wrote in order to create a dummy VLAN and assign all of the unused ports to it, plus some standard SSH security configuration.  Please, be gentle as this is my first time trying to write those scripts. And any enhancements are more that welcomed.

 

/*

.CHANGE_TEMPLATE_DESCRIPTION

  This change template configures dummy VLAN and assign unused switch ports (notconnect) to it . This was verified on Cisco 3750 switches.

.CHANGE_TEMPLATE_TAGS

  Cisco, IOS, VLAN Membership , unused ports

.PLATFORM_DESCRIPTION

  Cisco IOS

.PARAMETER_LABEL @ContextNode

  NCM Node

.PARAMETER_DESCRIPTION @ContextNode

  The node the template will operate on. (Cisco Switch)

.PARAMETER_LABEL @DummyVLAN

  Dummy VLAN ID to add and assign

.PARAMETER_DESCRIPTION @DummyVLAN

  Dummy VLAN ID you would like to add and assign.

*/

 

script ConfigureDummyVLANCiscoIOS (

NCM.Nodes @ContextNode,

int @DummyVLAN )

{

int @flag

@flag = 0

CLI

  {

  configure terminal

  vlan @DummyVLAN

  name Blackhole

  exit

  }

foreach(@itf in @ContextNode.Interfaces)

  {

 

       if (@itf.OperStatus == 'Up')

       {

            @flag=1

       }

       if (@itf.InterfaceDescription contains 'vlan')

       {

       @flag=1

       }

       if (@itf.InterfaceType != 6)

       {

       @flag=1

       }

 

       if (@flag==0)

       {

            CLI

            {

                 interface @itf.InterfaceDescription

                 switchport vlan @DummyVLAN

                 exit

            }

       }

       @flag=0

 

   }

 

}


Viewing all articles
Browse latest Browse all 20202

Trending Articles



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