Automation

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

By Elevate posted 07-19-2016 09:54

  

Question

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)?

Answer

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:

 

<vlans>
<vlan rename="rename" name="Green">
<name>Blue</name>
</vlan>
</vlans>

 

 


#netconf
#rename
#ScriptingHow-To
#Scripting
#How-To
0 comments
0 views

Permalink