Coordinate XML RPC Data Between Routing Engines
For SLAX version 1.0 and higher, you can get or set information between Routing Engines using a script.
One example of this could be updating utility MIB information on both Routing Engines, since no utility MIB data synchronization is provided by Junos OS.
You could open a connection using the IP address of the other Routing Engine's fxp0.0 interface, however, if that link is ever physically down (for example, it's plugged into a switch that's powered off), then this just won't work.
As of Junos OS Release 11.4R3 and 12.1R2, there's a better way.
To coordinate XML RPC data between routing engines, open a connection to the other Routing Engine by:
- specifying the private routing-instance "__juniper_private1__", and
- specifying the IP address of the other Routing Engine's em0.0 interface.
(RE0 IP address is 10.0.0.4, and RE1 IP address is 10.0.0.5)
The following is an example script that shows the same utility MIB data written to both RE0 and RE1 using this technique.
NOTE: You need to modify this to use your own values for $userid and $passwd.
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 /*********************************************************************/