JUNOS::Response - Response object from a remote Juniper box |
JUNOS::Response - Response object from a remote Juniper box
This example retrieves 'show chassis hardware' information and transforms
the input with XSLT. A JUNOS::Response object is returned by the
$jnx->get_chassis_inventory()
call.
use JUNOS::Device;
# 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();
This object encapsulates a response from a remote JUNOScript server. It is returned from a JUNOS::Device::request, JUNOS::Device::command, and all XML RPC methods within JUNOS::Device. It is a subclass of XML::DOM::Element.
new($DOC)
The XML::DOM object ($DOC) returned from the JUNOScript server.
getFirstError()
Returns a hash reference containing all of the errors caused by the call this object was generated in response to. Returns undef if no errors were encountered.
toString()
Returns a string-ified representation of this object.
translateXSLtoRelease($NAMESPACE, $XSLFILE, $TMPFILE)
Returns the name of the xsl file to transform the response data.
XSLT 1.0 requires that the xsl file must declare the a prefix with the default namespace from the XML data it transforms. Because the default namespace in all JUNOScript responses contains version information, the xsl file will have to adapt to the default namespace from routers running different versions of JUNOS.
This subroutine takes three input parameters: the prefix name ($NAMESPACE), xsl input file name ($XSLFILE) and xsl temp file name ($TMPFILE). It replaces the value of the prefix attribute in the input xsl file with the default namespace from the JUNOScript response and puts the result in the output xsl file. In some cases, it may have to remove the prefix for default namespace from the xsl input file because some JUNOScript responses from old versions of JUNOS may not contain default namespace (e.g. response for <get-bgp-neighbor-information> from pre-5.1 JUNOS).
If all is well, the name of the xsl file for transformation is returned. Otherwise, undef is returned. Please note that the returned xsl file can be the xsl input file or the temp file depending whether any changes are made on the xsl input file for transformation.
XML::DOM JUNOS::Device
Juniper Junoscript Perl Team, send bug reports, hints, tips, and suggestions to support@juniper.net.
Copyright (c) 2001 Juniper Networks, Inc. All rights reserved.
JUNOS::Response - Response object from a remote Juniper box |