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 routing, switching, and security
devices running Junos OS. The Net::Netconf::Manager
module provides an object-oriented interface for communicating with
a NETCONF server on devices running Junos OS, and 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 a device running Junos OS. 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.
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.
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.