Automation

Scripting How-To: Coordinate XML RPC data across routing engines in SLAX

By Elevate posted 08-08-2015 00:12

  

Coordinate XML RPC Data Across Routing Engines in SLAX

 

 For SLAX version 1.0 and higher, there may be times when your Junos OS Automation script needs to share information with another script in the other Routing Engine, and you don't want to rely on connectivity between each Routing Engine's fxp0 interface. This is a quick example of how to do just that. 

 

 One use case for this application might be updating utility MIB info on both Routing Engines (since there's no coordination between them). It might be possible to open a connection using the IP address of the other Routing Engine's fxp0.0 interface, but if that link is ever physically down (e.g., it's plugged into a switch that is powered off), it won't work. 

 

A better way is to open a connection to the other Routing Engine by:

 

  1. Specifying the private routing instance "__juniper_private1__" and
  2. Specifying the IP address of the other Routing Engine's em0.0 interface. The IP address for RE0 is 10.0.0.4. The IP address for RE1 is 10.0.0.5 .

The script below is an annotated example script that demonstrates writing the same Utility MIB data to both RE0 and RE1 using this technique.

 

01	version 1.0;
02	 
03	ns junos = "http://xml.juniper.net/junos/*/junos";
04	ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
05	ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
06	ns func extension = "http://exslt.org/functions";
07	 
08	import "../import/junos.xsl";
09	 
10	param $re0;
11	param $re1;
12	 
13	var $userid = "changeme";    /* change this */
14	var $passwd = "changeme2";   /* change this, too. */
15	 
16	var $routing-instance = "__juniper_private1__";   /* this is important */
17	 
18	/* session optinos for the rmote jcs:open() */
19	var $session-options = {
20	           <username> $userid;
21	           <password> $passwd;
22	           <routing-instance>$routing-instance;
23	       }
24	 
25	       
26	/*
27	* Need to know which RE we're running on in order to determins the IP of the "other" RE.
28	*  - re0 em0.0 is always 10.0.0.4
29	*  - re1 em0.0 is always 10.0.0.5
30	*/
31	 
32	var $rem-ip = {
33	    if ($junos-context/routing-engine-name == 're0'){
34	        expr "10.0.0.5";
35	    }
36	    else if($junos-context/routing-engine-name == 're1'){
37	        expr "10.0.0.4";
38	    }
39	    else {
40	        expr "INVALID";
41	    }
42	}
43	 
44	match / {
45	    <op-script-results> {  
46	 
47	    if ($rem-ip == "INVALID") {
48	        expr jcs:output("ERROR: Unable to determine other RE IP address. Exiting.");
49	        <xsl:message terminate="yes">;
50	    }
51	 
52	    var $rcon = jcs:open($rem-ip,$session-options);
53	        var $con = jcs:open();
54	        if (not($rcon)) {
55	            expr jcs:output("Error connecting to mgd at ", $rem-ip);
56	        }
57	        if (not($con)) {
58	            expr jcs:output("Error connecting to mgd.");
59	        }
60	 
61	        call set-instance($connection = $con, $instance = "re0", $type = 'string', $value = $re0);
62	        call set-instance($connection = $rcon, $instance = "re0", $type = 'string', $value = $re0);
63	        call set-instance($connection = $con, $instance = "re1", $type = 'string', $value = $re1);
64	        call set-instance($connection = $rcon, $instance = "re1", $type = 'string', $value = $re1);
65	    }
66	}
67	 
68	/*********************************************************************************************************/
69	 
70	 
71	/*******************************************************************/
72	/* set-instance - template to set mib instance info in utility mib */
73	template set-instance($connection, $instance, $type, $value) {
74	     var $rpc = {
75	         <request-snmp-utility-mib-set> {
76	             <instance> $instance;
77	             <object-type> $type;
78	             <object-value> $value;
79	         }
80	     }
81	     var $res = jcs:execute ($connection, $rpc);
82	     if ($res//xnm:error) {
83	         <xsl:message terminate="yes"> "Error setting Utility MIB instance: " _ $results/..//xnm:error/message;
84	     }
85	}
86	/*********************************************************************/

 

 


#rpc
#xml
#Slax
#routingengine
#ScriptingHow-To
#How-To
0 comments
0 views

Permalink