Blog Viewer

Scripting How-To: Scripting Equivalent of the rename Command in Configuration Mode

By Erdem posted 07-19-2016 09:54



The problem with using a restricted keyword for security zones can be manually fixed by issuing the following command in configuration mode and subsequently changing all the references to the keyword:


rename security zones security-zone restricted-keyword to security-zone safe-name

Is it possible to replicate the same rename action through a script (to change the zone name without disturbing the contents)?


If using NETCONF with PERL, use the EZXML module that allows you to create XML to send to the Juniper Networks device easily. For more information, see the "Junos_XML_API_Day_One_Training_Workshop" document with the NETCONF downloads for at least the more recent versions of Junos OS.

From that document:

The following is equivalent to the CLI command “rename vlans Blue to Green”:


$vlan = $config->vlans->vlan;
$vlan->name( ‘Blue’ );
junosRename $vlan ( ‘Green’ );


Resulting XML:


<vlan rename="rename" name="Green">