Automation

last person joined: yesterday 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  scripting equivalent of rename

    Posted 02-28-2013 10:29

    Is there a scripting equivalent of a rename command in the configure mode? There is a problem with using a restricted keyword for security zones, which can be manually fixed by issuing the following command:

     

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

     

    in configure mode, and subsequently change all the references to it. Is it possible to replicate the same rename action via script (change the zone name without disturbing the contents)?



  • 2.  RE: scripting equivalent of rename
    Best Answer

    Posted 02-28-2013 12:29

    Yes it looks like there is.  What method do you plan on using to script this?  If using NETCONF with PERL, there is a handy EZXML module that allows you to create the XML to send the Juniper device pretty easy.  It's discussed in the "Junos_XML_API_Day_One_Training_Workshop document that is packaged with the Netconf downloads for at least the more recent versions of Junos.

     

    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>



  • 3.  RE: scripting equivalent of rename

    Posted 03-04-2013 12:26

    Thanks B2! I also stumbled across the command in my research. To answer your question, this will be an op script file written in SLAX. The following script is a smaller subset of what I came up with.

     

    version 1.0;
    ns junos = "http://xml.juniper.net/junos/*/junos";
    ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
    ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
    import "../import/junos.xsl";
    
    match / {
    	<op-script-results> {
        var $rename-mgmt-zone = {
            <configuration> {
                <security> {
                    <zones> {
                        <security-zone rename="rename" name="mgmt"> {
                            <name> "management";
                            }
                        }
                    }
                }
            }
        var $conn = jcs:open();
        var $results01 := {
            call jcs:load-configuration( $connection = $conn,
            $configuration = $rename-mgmt-zone );
        }
        if ( $results01//xnm:error ) {
            for-each( $results01//xnm:error ) {
                <output> message;
            }
        }
        var $close-results = jcs:close($conn);
    	}
    }