Example: Getting An Inventory Of Hardware Components - Juniper JUNOS OS 10.3 - XML MANAGEMENT PROTOCOL GUIDE 6-30-2010 Manual

Junos xml management protocol guide
Hide thumbs Also See for JUNOS OS 10.3 - XML MANAGEMENT PROTOCOL GUIDE 6-30-2010:
Table of Contents

Advertisement

Copyright © 2010, Juniper Networks, Inc.
argument3 => value3 ,
...);
The application then invokes the method, defining the
JUNOS::Response
object that the Junos XML protocol server returns in response to the
request (the object is defined in the
Perl distribution):
my $res = $jnx-> method (%args);
If the attempt to send the request failed, the application prints an error message and
closes the connection:
unless ( ref $res ) {
$jnx->request_end_session();
$jnx->disconnect();
print "ERROR: Could not send request to $hostname\n";
}
If there was an error in the Junos XML protocol server's response, the application prints
an error message and closes the connection. The
the
module (
JUNOS::Response
Perl distribution.
my $err = $res->getFirstError( );
if ($err) {
$jnx->request_end_session( );
$jnx->disconnect( );
print "ERROR: Error for $hostname: " . $err->{message} . "\n";
}

Example: Getting an Inventory of Hardware Components

The
get_chassis_inventory.pl
hardware components installed in a routing, switching, or security platform. It is equivalent
to issuing the
show chassis hardware detail
After establishing a connection to the Junos XML protocol server, the script defines
as the request to send and includes the
get_chassis_inventory
my $query = "get_chassis_inventory";
my %queryargs = ( detail => 1 );
The script sends the query and assigns the results to the
tests on the results, and prints an error message if it cannot send the request or if errors
occurred when executing it. If no errors occurred, the script uses XSLT to transform the
results. For more information, see "Parsing and Formatting an Operational Response"
on page 226.
# send the command and receive a XML::DOM object
my $res = $jnx->$query( %queryargs );
unless ( ref $res ) {
die "ERROR: $deviceinfo{hostname}: failed to execute command $query.\n";
}
# Check and see if there were any errors in executing the command.
my $err = $res->getFirstError( );
if ($err) {
print STDERR "ERROR: $deviceinfo{'hostname'} - ", $err->{message}, "\n";
} else {
Chapter 9: Writing Junos XML Protocol Perl Client Applications
lib/JUNOS/Response.pm
getFirstError
lib/JUNOS/Response.pm
script retrieves and displays a detailed inventory of the
command.
variable to point to the
$res
file in the Junos XML protocol
function is defined in
) in the Junos XML protocol
argument:
detail
variable. It performs two
$res
221

Advertisement

Table of Contents
loading

This manual is also suitable for:

Junos os

Table of Contents