Example: Request an Inventory of Hardware Components Using a NETCONF Perl Client Application
The NETCONF Perl distribution includes several sample Perl scripts
to perform various functions on devices running Junos OS. The get_chassis_inventory.pl script retrieves and displays
a detailed inventory of the hardware components installed in a routing,
switching, or security platform. It is equivalent to issuing the show chassis hardware detail
operational mode
command in the Junos OS command-line interface (CLI). This topic describes
the portion of the script that executes the query.
Prior to Junos OS Release 16.1, every Junos OS release included a new, release-dependent version of the NETCONF Perl client. Beginning in Junos OS Release 16.1, the NETCONF Perl client is release-independent, is hosted on GitHub and CPAN, and can manage devices running any version of the Junos OS release. The sample scripts in the release-dependent versions of the NETCONF Perl distribution differ from those in the release-independent version hosted on GitHub and CPAN.
After establishing a connection to the NETCONF server,
the script sends the get_chassis_inventory
request and includes the detail
argument.
my $query = "get_chassis_inventory"; my %queryargs = ( 'detail' => 'True' );
When using the release-dependent NETCONF Perl distribution, to include a fixed-form option when invoking a method, set the option equal to the value 1 (one).
The script sends the query and assigns the return value to the $res
variable. The script first prints the RPC request
and response to standard output, then it prints the response to the
specified file. The script then checks for and prints any error encountered.
my $res; # Netconf server response # send the command and get the server response my $res = $jnx->$query(%queryargs); print "Server request: \n $jnx->{'request'}\n Server response: \n $jnx->{'server_response'} \n"; # print the server response into xmlfile print_response($xmlfile, $jnx->{'server_response'}); # See if you got an error if ($jnx->has_error) { croak "ERROR: in processing request \n $jnx->{'request'} \n"; } else { print "Server Response:"; print "$res"; } # Disconnect from the Netconf server $jnx->disconnect();
Change History Table
Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.