cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 9

Ok, so maybe this is a dumb question....

Jump to solution

Quite frankly, I suck at writing these config change thingies.... But they're really useful if I can get them to work. I need to add the layer 2 configuration for more than one vlan on all of my Nexus 5Ks. It's a huge fabricpath & I really don't want to go to each switch to do this. I could just run a script, I know, but it would be awesome if I could just use variables instead of having to re-write the script. I know I have a template for adding a single L2 vlan:

.CHANGE_TEMPLATE_DESCRIPTION

        This template creates a new L2 vlan

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

        Vlan ID

.PARAMETER_DESCRIPTION @NewVlanID

        Create new vlan ID

.PARAMETER_LABEL @VlanDescription

        Vlan Name

.PARAMETER_DESCRIPTION @VlanDescription

        Enter the name of the new vlan

       

*/

script CreateNewVlan (

                                            NCM.Nodes @ContextNode,

                                            string @NewVlanID,

                                            string @VlanDescription

                                                                          )

{

    // Enter configuration mode

    CLI

    {

       configure terminal

    }

        // Create vlan

        CLI

        {

           vlan @NewVlanID

           name @VlanDescription

           mode fabricpath

           end

                 

        }

    

                                                      

So my question is how do I get that to work for multiple vlans? I'm guessing it's going to be some kind of for loop but I have no idea how to get that to work....

0 Kudos
1 Solution

You can declare an array of int [] as template input variable and then use it in the template.

Example:

script BaseChangeTemplate(NCM.Nodes @ContextNode, int [] @VlansToSet)

View solution in original post

7 Replies
Level 12

Something like this:

script BaseChangeTemplate(NCM.Nodes @ContextNode)

{

    foreach (@interfaceItem in @ContextNode.Interfaces)                        Iterate through all interfaces of the node.

    {

        if (@interfaceItem.InterfaceDescription contains 'blabla')             Test the description.

        {

          CLI

          {

            command1

            command2

          }

        }

    }

}


You can find all sorts of good suggestions here: https://thwack.solarwinds.com/community/solarwinds-community/product-blog/blog/2012/12/18/a-few-tips... 

Yes, I saw that example... But I'm not quite sure how I'd apply it to creating multiple new vlans.... The commands would be something like:

vlan 0123

mode fabricpath

name blahblahblahblah

exit

vlan 4567

mode fabricpath

name blahblahblahblah

exit

And since they don't already exist in the NCM.VLANS table.... Now you see why I don't get these at all.

0 Kudos

Have you inventoried your devices? VLAN is included here SolarWinds Information Service data entities

You can check this page for better detail on the Config change template details

Your script would have something like the following:

{

// Enter configuration mode

     CLI

          { configure terminal }

}

foreach ( <insert here> )

{

CLI

    {

          vlan 0123

          mode fabricpath

          name

    }

}

{

CLI

    {

          vlan 4567

          mode fabricpath

          name blahblahblahblah

    }

}

// Exit configuration mode

{

CLI

     { exit }

}

I think the point of the trouble is that the vlans don't exist yet, so they cannot be inventoried.  I don't believe you can feed arrays of values into the CCT engine.  It knows how to loop through existing nodes and existing interfaces but doesn't seem to have a method of feeding it any new arrays of things to loop through.

I suspect that you would need to schedule a separate config change template for each new vlan you want to create, in which case executing a script snippet might be simpler, or a compliance report but I suspect that building that out might be pretty tedious as well.

- Marc Netterfield, Github
0 Kudos

You can declare an array of int [] as template input variable and then use it in the template.

Example:

script BaseChangeTemplate(NCM.Nodes @ContextNode, int [] @VlansToSet)

View solution in original post

Good to know, when we input the list would we be using a comma as the delimiter?

- Marc Netterfield, Github

Correct!