graceful_shutdown($jnx, $xmlfile, STATE_LOCKED, REPORT_FAILURE);
}
$err = $res->getFirstError();
if ($err) {
print "ERROR: can't load the configuration from $xmlfile. Reason: $err->{message}\n";
graceful_shutdown($jnx, $xmlfile, STATE_CONFIG_LOADED, REPORT_FAILURE);
}
Here is another example. It retrieves 'show chassis hardware' information and transforms the input with XSLT.
# connect TO the JUNOScript server
$jnx = new JUNOS::Device(hostname => "router11",
login => "johndoe",
password => "secret",
access => "telnet");
unless ( ref $jnx ) {
die "ERROR: $deviceinfo{hostname}: can't connect.\n";
}
# send the command and receive a XML::DOM object
my $res = $jnx->get_chassis_inventory(detail => 1);
unless ( ref $res ) {
die "ERROR: $deviceinfo{hostname}: can't execute command $query.\n";
}
# Check and see if there were any errors in executing the command.
# If all is well, output the response using XSLT.
my $err = $res->getFirstError();
if ($err) {
print STDERR "ERROR: $deviceinfo{'hostname'} - ", $err->{message}, "\n";
} else {
#
# Now do the transformation using XSLT.
#
my $xmlfile = "$deviceinfo{hostname}.xml";
$res->printToFile($xmlfile);
my $nm = $res->translateXSLtoRelease('xmlns:lc', $xslfile, "$xslfile.tmp");
if ($nm) {
my $command = "xsltproc $nm $deviceinfo{hostname}.xml";
system($command);
} else {
print STDERR "ERROR: Invalid XSL File $xslfile\n";
}
}
# always close the connection
$jnx->request_end_session();
$jnx->disconnect();
=head1 DESCRIPTION
This module implements an object oriented interface to the JUNOScript (tm)
XML-based API supported by Juniper Networks. Objects of this class represent
the local side of connection to a Juniper Networks device running JUNOS,
over which the JUNOScript protocol will be spoken. JUNOScript is
described in detail in the JUNOScript API Guide and Reference.
=head1 CONSTRUCTOR
new(%ARGS)
The constructor accepts a hash table %ARGS containing the following keys:
hostname
Name of Juniper box to connect to.
login
Username to log into box as.
password
Password for login username.
access
Access method - can be 'telnet' or 'ssh' or 'ssl'.
Do_Not_Connect
if set to true a connection to a Juniper box
will not be establish upon object creation. You then
must call the 'connect' function to explicitly create the
connection
namespace-action
if you don't want to deal with namespace, just set this
to either 'remove-namespace' or 'update-namespace'. This is
handy when you don't want to care about declaring the XML namespace
in your XSL file(s). 'remove-namespace' means removing all
namespace declarations and schemaLocation from the the responses.
'update-namespace' means remove all namespaces and replace
schemaLocation with noNamespaceSchemaLocation.
Additional keys specific to the access method are processed by the access method object (e.g. JUNOS::Access::telnet). See
the perldoc of the access method class for the definition of these additional keys.
=head1 METHODS
command($COMMAND)
Send the raw command string from $COMMAND to the remote Juniper box.
This is a 'mostly unsupported' way of getting to any JUNOS
command that is currently unsupported in JUNOScript.
=7= |