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.

See the following sections for more information:

Mapping Junos OS Commands and NETCONF Operations to Perl Methods

Most operational commands have a corresponding Junos XML request tag. You can find the Junos XML request tags for operational commands by using the Junos XML API Explorer. You can also display the Junos XML request tags in 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, issue the command and include the | display xml rpc option. 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.