Write NETCONF Perl Client Applications
The Juniper Networks NETCONF Perl client enables programmers familiar with the Perl programming
language to create their own Perl applications to manage and configure Junos devices.
The Net::Netconf::Manager
module provides an object-oriented interface
for communicating with a NETCONF server on managed devices. The module enables you to
connect to the device, establish a NETCONF session, and execute operational and
configuration requests.
The following outline lists the basic tasks involved in writing a NETCONF Perl client application that manages Junos devices. Each task provides a link to more detailed information about performing that task.
- Import Perl Modules and Declare Constants—Import Perl Modules and Declare Constants in NETCONF Perl Client Applications
- Connect to the NETCONF Server—Connect to the NETCONF Server in Perl Client Applications and Collect Parameters Interactively in NETCONF Perl Client Applications
- Submit Requests to the NETCONF Server—Submit a Request to the NETCONF Server in Perl Client Applications
- Parse and Format the Response from the NETCONF Server—Parse the NETCONF Server Response in Perl Client Applications
- Close the Connection to the NETCONF Server—Close the Connection to the NETCONF Server in Perl Client Applications
The tasks are illustrated in the following example, which
uses the Net::Netconf::Manager
object to
request information from a device running Junos OS. The example presents
the minimum code required to execute a simple query.
Import required modules and declare constants.
use strict; use Carp; use Net::Netconf::Manager;
Create a
Manager
object and connect to the device.my %deviceinfo = ( access => "ssh", login => "johndoe", password => "password123", hostname => "Router1" ); my $jnx = new Net::Netconf::Manager(%deviceinfo); unless ( ref $jnx ) { croak "ERROR: $deviceinfo{hostname}: failed to connect.\n"; }
Construct the query and send it to the NETCONF server.
my $query = "get_chassis_inventory"; my $res = $jnx->$query();
Process the response as needed.
print "Server response: \n $jnx->{'server_response'} \n";
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.