A Few Tips and Tricks When Creating NCM Config Change Templates
As you probably know, Config Change Templates (CCT) are a very powerful feature of the Network Configuration Manager. On top of the Execute Script functionality, they add flow control statements such as conditions and loops. You can also use custom properties, define input parameters etc. -- please see for details. Just remember that your device must be inventoried in NCM in order to be targeted with Config Change Templates.
You can use one of the templates provided with NCM out of the box, import from thwack, or create your own from scratch. Today I would like to show you a few tips and tricks that you might find useful when creating your own, advanced templates.
How to Use Special Symbols in CLI Statements
Imagine you need to include the following command in a CLI statement of your CCT:
show clock | append disk0:show_tech
You can not do it directly -- the pipe symbol breaks the script. Here is the trick:
script BaseChangeTemplate(NCM.Nodes @ContextNode)
{
string @PipeSymbol='|' Define a string variable to carry the special symbol.
CLI
{
show clock @PipeSymbol append disk0:show_tech Place the variable in the command.
}
}
The same trick can be used for other special characters such as the '@' symbol.
How to Add Variables to CLI Statements
You may want to include certain variables, that you normally use e.g. in device templates, in your CCT. This approach helps you keep your template as device-independent as possible. Additionally, you can include e.g. IP address (of your TFTP server, for example) in a clean way which will not make you modify the CCT source code when this IP address changes. The trick is basically identical to the previous case. The following fragment can be used e.g. when handling firmware.
script BaseChangeTemplate(NCM.Nodes @ContextNode)
{
string @myTFTPImage='${StorageAddress}' + '/image.bin' ${StorageAddress} is the IP address of TFTP server that comes with NCM. It is used e.g. in device templates for config downloads.
CLI
{
copy tftp://@myTFTPImage flash You do not have to hard-code the IP address in the command.
...
}
}
Resulting script:
copy tftp://${StorageAddress}/image.bin flash
Using Custom Properties in CCTs
Unlike variables, custom properties are tied with nodes, and therefore can be referenced via the node parameter:
script BaseChangeTemplate (NCM.Nodes @ContextNode)
{
CLI
{
show @ContextNode.MyCustomProperty
}
}
Details about the use of custom properties in Config Change Templates is described in .
Configuring Specific Interfaces
A customer once asked how he could run a command on an interface with a specific IP address. (He wanted to set logging source interface on a Cisco router.) All you have to do is to iterate through interfaces and their IP addresses:
script BaseChangeTemplate(NCM.Nodes @ContextNode)
{
foreach (@interfaceItem in @ContextNode.Interfaces) Iterate through all interfaces of the node.
{
foreach(@ip in @interfaceItem.IpAddresses) Iterate through all IP addresses of that interface.
{
if (@ip.IPAddress contains '10.199.2.1') Test the IP address.
{
CLI
{
logging source-interface @interfaceItem.InterfaceDescription Set logging source.
}
}
}
}
}
Simultaneous Execution of CCTs
Last but not least, you can configure the number of devices for that can execute in parallel. In the Web UI (NCM v7.1), go to Settings -> NCM Settings -> Configs -> Config Transfer -> Simultaneous Downloads/Uploads.
The default value is 10, i.e. when you run a template on 50 devices, the task will be carried out in 5 batches (10 devices each).
Top Comments