when scripting and interrogating interfaces in a for loop, the interface list always comes up blank, as if the data is missing or the schema has changed and ContextNode[].Interfaces is something different. Is there a known fix for this? Here's the script!!
/*
.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 @ItfDescriptionMatchValue
If Interface Description Matches
.PARAMETER_DESCRIPTION @ItfDescriptionMatchValue
Enter the criteria that will trigger the change. If the interface property matches the trigger, a change config for the selected interface will be generated.
*/
script ChangeInterfacesBasedOnDescription (
NCM.Nodes @ContextNode,
string @ItfDescriptionMatchValue
)
{
// Make a backup of the running config and Enter configuration mode
CLI
{
copy running-config b4ghostfix.cfg
b4ghostfix.cfg
configure terminal
}
int @MatchFound
@MatchFound = 0
// Loop through selected interfaces
foreach (@interfaceItem in @ContextNode.Interfaces)
{
if (@interfaceItem.InterfaceAlias contains @ItfDescriptionMatchValue)
{
// Set command
CLI
{
interface @interfaceItem.InterfaceAlias
// insert negating commands here
//
no authentication periodic
no switchport port-security violation restrict
no switchport port-security aging type inactivity
no authentication timer reauthenticate server
no authentication timer restart 3600
no authentication timer unauthorized 3600
no dot1x timeout tx-period 5
no dot1x timeout supp-timeout 10
no dot1x max-req 3
no dot1x max-reauth-req 3
no cdp enable
no authentication timer reauthenticate server
no authentication timer restart 3600
no authentication timer unauthorized 3600
//
// Insert commands with replaced parameters here
//
authentication order dot1x mab
authentication violation replace
//
// Insert new commands here
//
carrier-delay msec 0
}
CLI
{
exit
}
@MatchFound = 1
}
}
if (@MatchFound != 1)
{
CLI
{
NO MATCHES FOUND
}
}
// Exit configuration mode
CLI
{
exit
}
}