[j-nsp] XML sample request

Phil Shafer phil@juniper.net
Mon, 02 Dec 2002 11:24:02 -0500


Neil Stirling writes:
>Specifically I need some help with establishing a connection to a Juniper
>through the JUNOscript session and then using XML to query the router.

Neil,
 I answered some of this in the response to your unicast email over
Thanksgiving vacation, but wanted to follow up on this specific request.

The Junoscript API allows a client application or script to connect
to the router over a number of protocols and perform a series of RPCs.
The client can use traditional login session (ssh, telnet) or a simple
SSL-based access mechanism. The RPCs are a representation of the JUNOS UI
in XML, where command line requests are represented as XML RPCs.

Here's an _extremely_ simple example: a shell script to activate the login
for juniper support personnel. No error handling, no output rendering, just
the connection and rpc basics. In a shell script, no less. (A shell script
is not really well suited for this sort of task, but it does makes for a
nice, simple, self-contained example).

#!/bin/sh
# invoke as:   this.sh <router-name> <login> (active | inactive)

ROUTER=$1
LOGIN=$2
STATUS=$3

INFILE=/tmp/simple-in-$$.xml
OUTFILE=/tmp/simple-out-$$.xml

cat > $INFILE << LAST_LINE
<?xml version="1.0"?>
<junoscript version="1.0">
  <rpc>
    <lock-configuration/>
  </rpc>
  <rpc>
    <load-configuration>
      <configuration>
        <system>
          <login>
            <user $STATUS="$STATUS">
              <name>$LOGIN</name>
            </user>
          </login>
        </system>
      </configuration>
    </load-configuration>
  </rpc>
  <rpc>
    <commit-configuration/>
  </rpc>
  <rpc>
    <unlock-configuration/>
  </rpc>
</junoscript>
LAST_LINE

exec ssh $ROUTER xml-mode < $INFILE > $OUTFILE

The output file can be tested, etc using an xslt processor (like xsltproc).

Hope this helps.....

Thanks,
 Phil