Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Understanding the NETCONF Perl Client and Sample Scripts

 

Devices running Junos OS support the NETCONF XML management protocol, which enables client applications to request and change configuration information on the devices. The NETCONF protocol uses an Extensible Markup Language (XML)-based data encoding for the configuration data and remote procedure calls. The Juniper Networks NETCONF Perl API enables programmers familiar with the Perl programming language to create their own Perl applications to manage devices running Junos OS over NETCONF.

Note

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 modules and 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.

This section includes the following topics:

NETCONF Perl Client Modules

Table 1 summarizes the modules in the release-independent version of the NETCONF Perl library. The Net::Netconf::Manager module provides an object-oriented interface for communicating with the NETCONF server on devices running Junos OS, and enables you to easily connect to the device, establish a NETCONF session, and execute operational and configuration requests. Client applications only directly invoke the Net::Netconf::Manager object. When the client application creates a Manager object, it supplies the device name and the login name to use when accessing the device. The login name determines the client application's access level on the device.

Table 1: NETCONF Perl Modules

Module

Description

Access

Creates an Access object based on the access method type specified when instantiating the object. The module is responsible for calling the connect() method to establish a session with the NETCONF server at the destination host and for exchanging hello packets with the server after the session is established.

Constants

Declares all NETCONF constants.

Device

Implements an object-oriented interface to the NETCONF API supported by devices running Junos OS. Objects of this class represent the local side of the connection to the device, which communicates to the client using the NETCONF protocol.

EzEditXML

Facilitates the development of XML documents for both operational and configuration requests.

The module uses XML::LibXML as a base library, but provides Junos OS CLI-specific features to manipulate the configuration, corresponding to the CLI commands: delete, activate, deactivate, insert, and rename.

Manager

Instantiates and returns a NETCONF or Junos XML Device object depending on which server is requested.

SAXHandler

SAX-based parser that parses responses from the NETCONF server.

SSH

Provides SSH access to a Net::Netconf::Access instance, and manages the SSH connection with the destination host. The underlying mechanism for managing the SSH connection is based on OpenSSH.

Trace

Provides tracing levels and enables tracing based on the requested debug level.

Note

The following module is new in the release-independent version of the NETCONF Perl client: EzEditXML.

The following modules were removed in the release-independent version of the NETCONF Perl client: Transform, Plugins, and Version.

Client applications can also leverage Perl modules in the public domain to ease the development of NETCONF Perl client applications. Because NETCONF uses XML-based data encoding, client applications can make use of the many Perl modules that manipulate XML data.

You can use the NETCONF Perl client to create Perl applications that connect to a device, establish a NETCONF session, and execute operations. The communication between the client and the NETCONF server on the device through the NETCONF Perl API involves the following steps:

  • Establishing a NETCONF session over SSHv2 between the client application and the NETCONF server on the device running Junos OS.

  • Creating RPCs corresponding to requests and sending these requests to the NETCONF server.

  • Receiving and processing the RPC replies from the NETCONF server.

Sample Scripts

The NETCONF Perl distribution includes an examples directory with the following sample scripts that illustrate how to use the modules to perform various functions. For instructions on running the scripts, see the README file in the NETCONF Perl GitHub repository at https://github.com/Juniper/netconf-perl.

  • diagnose_bgp/diagnose_bgp.pl—Illustrates how to monitor the status of the device and diagnose problems. The script extracts and displays information about a device's unestablished Border Gateway Protocol (BGP) peers from the full set of BGP configuration data.

  • get_chassis_inventory/get_chassis_inventory.pl—Illustrates how to use a predefined query to request information from a device. The sample script invokes the get_chassis_inventory query with the detail option to request the same information as returned by the Junos XML <get-chassis-inventory><detail/></get-chassis-inventory> request and the CLI operational mode command show chassis hardware detail.

  • edit_configuration/edit_configuration.pl—Illustrates how to configure the device by loading a file that contains configuration data formatted with Junos XML tag elements. The distribution includes a sample configuration file, config.xml; however, you can specify a different configuration file on the command line when you invoke the script.

Release History Table
Release
Description
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 modules and 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.