Monday, April 21, 2014

JUNOS scripts on a EX Virtual Chassis needs each potential Routing Engine to have a copy of all scripts in /var/db/scripts/

How do we go about copying these to all devices in a Virtual Chassis?

normally you would use the file copy command:

run file copy /var/db/scripts/commit/script.slax fpc0:/var/db/scripts/commit/

This is a manual process. So let's try to automate this. The name of the test script is called "vc-copy.slax" you could create an argument in the script to pass the file name to the op script.

This script will look at the member id and see which fpcs are present to copy the scripts.

jnpr@EX4200-VC1# run show virtual-chassis status  

Virtual Chassis ID: 030b.bd6f.ed90
                                          Mastership            Neighbor List
Member ID  Status   Serial No    Model    priority    Role      ID  Interface
0 (FPC 0)  Prsnt    BP0208192416 ex4200-48t      200  Master*    3  vcp-0    
                                                                 1  vcp-1    
1 (FPC 1)  Prsnt    BP0208377206 ex4200-48t      199  Backup     0  vcp-0    
                                                                 2  vcp-1    
2 (FPC 2)  Prsnt    BP0208377298 ex4200-48t      198  Linecard   1  vcp-0    
                                                                 3  vcp-1    
3 (FPC 3)  Prsnt    BP0208192367 ex4200-48t      128  Linecard   2  vcp-0    
                                                                 0  vcp-1    

Member ID for next new member: 4 (FPC 4)

jnpr@EX4200-VC1# run file list /var/db/scripts/op


jnpr@EX4200-VC1# run op vc-copy                          

jnpr@EX4200-VC1# run file list fpc1:/var/db/scripts/op


jnpr@EX4200-VC1# run file list fpc2:/var/db/scripts/op  


version 1.0;

ns junos = "*/junos";
ns xnm = "";
ns jcs = "";

import "../import/junos.xsl";

match / {
    <op-script-results> {
        <output method = "text"> {
            var $rpc = <command> "show virtual-chassis status";

            var $out = jcs:invoke($rpc);
            for-each ($out//member){
            var $fpc = ./fpc-slot;
            var $strip-space = translate($fpc, ' ', '');
            var $strip-left = translate($strip-space, '( ', '');
            var $strip-right = translate($strip-left, ')', ''); 
            var $result = translate($strip-right, 'FPC', 'fpc');

            var $dest = concat ($result, ':/var/db/scripts/op/vc-copy.slax'); 
            expr $dest _ "\n";

            var $ftp = {
                         <file-copy> {
                           <source> "/var/db/scripts/op/vc-copy.slax";
                           <destination> $dest;
            var $exec = jcs:invoke($ftp);   


No comments:

Post a Comment