Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Submit a Request to the NETCONF Server in Perl Client Applications

In a NETCONF Perl client application, after establishing a connection to the NETCONF server, the client application can execute operational or configuration commands on a device running Junos OS to request operational information or change the configuration. The NETCONF Perl API supports a set of methods that correspond to CLI operational mode commands and NETCONF configuration operations. To execute a command, the client application invokes the Perl method corresponding to that command.

Note:

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 release-independent version of the NETCONF Perl client can invoke any method that has a corresponding Junos XML request tag.

Prior to Junos OS Release 16.1, every Junos OS release included a new, release-dependent version of the NETCONF Perl client. Each version of the software supported a set of methods that corresponded to specific CLI operational mode commands and operations on configuration objects. You can view the list of operational methods supported in that version of the client by examining the files stored in the lib/Net/Netconf/Plugins/Plugin/release directory of the NETCONF Perl distribution. The set of methods that correspond to operations on configuration objects is defined in the lib/Net/Netconf/Plugins.pm file of the distribution.

See the following sections for more information:

Mapping Junos OS Commands and NETCONF Operations to Perl Methods

All operational commands that have Junos XML counterparts are listed in the Junos XML API Operational Developer Reference. You can also display the Junos XML request tag elements for any operational mode command that has a Junos XML counterpart on the CLI. Once you obtain the request tag, you can map it to the corresponding Perl method name.

To display the Junos XML request tags for a command in the CLI, include the | display xml rpc option after the command. The following example displays the request tag for the show route command:

You can map the request tag for an operational command to a Perl method name. To derive the method name, replace any hyphens in the request tag with underscores, and remove the enclosing angle brackets. For example, the <get-route-information> request tag maps to the get_route_information method name.

Similarly, NETCONF protocol operations map to Perl method names in the same manner. For example, the <edit-config> operation maps to the edit_config method name.

Providing Method Options

Perl methods can have one or more options. The following section describes the notation that an application uses to define a method’s options in a NETCONF Perl client application.

  • A method without options is defined as $NO_ARGS, as in the following entry for the get_autoinstallation_status_information method:

    To invoke a method without options, the client application follows the method name with an empty set of parentheses, as in the following example:

  • A fixed-form option is defined as type $TOGGLE. In the following example, the get_ancp_neighbor_information method has two fixed-form options, brief and detail:

    To include a fixed-form option when invoking a method, set the option equal to the string 'True', as in the following example:

    Note:

    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).

  • An option with a variable value is defined as type $STRING. In the following example, the get_cos_drop_profile_information method takes the profile_name argument:

    To include a variable value when invoking a method, enclose the value in single quotes, as in the following example:

  • A set of configuration statements or corresponding tag elements is defined as type $DOM. In the following example, the get_config method takes a set of configuration statements (along with two attributes):

    A DOM object is XML code:

    This generates the following RPC request:

A method can have a combination of fixed-form options, options with variable values, and a set of configuration statements. For example, the get_forwarding_table_information method has four fixed-form options and five options with variable values:

Submitting a Request

The following code illustrates the recommended way to send a configuration request to the NETCONF server and shows how to handle error conditions. The $jnx variable is defined to be a NET::Netconf::Manager object. The sample code, which is taken from the edit_configuration.pl sample script, locks the candidate configuration, loads the configuration changes, commits the changes, and then unlocks the configuration database and disconnects from the NETCONF server. You can view the complete edit_configuration.pl script in the examples/edit_configuration directory in the NETCONF Perl GitHub repository at https://github.com/Juniper/netconf-perl.

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.

Release
Description
16.1
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 release-independent version of the NETCONF Perl client can invoke any method that has a corresponding Junos XML request tag.