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

Administrators familiar with Perl can use the NETCONF Perl client API to create Perl applications that manage Junos devices using NETCONF.

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

The NETCONF Perl client is hosted on GitHub and CPAN. It is release-independent, and it can manage devices running any version of Junos OS or Junos Evolved. The following sections discuss the NETCONF Perl client modules and sample scripts.

NETCONF Perl Client Modules

Table 1 summarizes the modules in the NETCONF Perl library. The Net::Netconf::Manager module provides an object-oriented interface for communicating with the NETCONF server on Junos devices. The module 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 and devices running Junos OS Evolved. 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.

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 use 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 Junos device.

  • Creating RPCs corresponding to requests and sending the 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 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. The query requests the same information as returned by the Junos XML <get-chassis-inventory><detail/></get-chassis-inventory> request or 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 Junos XML-formatted configuration data. 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.