Related Documentation
Submitting a Request to the NETCONF Server in NETCONF Perl Client Applications
In a NETCONF Perl Client application, after establishing a connection to a NETCONF server, your application can submit one or more requests by invoking the Perl methods that are supported in the version of the NETCONF XML protocol and Junos XML API used by the application:
- Each version of software supports a set of methods that
correspond to CLI operational mode commands (later releases generally
support more methods). For a list of the operational methods supported
in the current version, see the files stored in the
lib\Net\Netconf\Plugins\Plugin\releasedirectory of the NETCONF Perl distribution (release is the Junos OS version code, such as 6.1R1 for the initial version of Junos OS Release 6.1). The files have names in the formatpackage_methods.pl, where package is a software package. - The set of methods that correspond to operations on configuration
objects is defined in the
lib/Net/Netconf/Plugins.pmfile in the NETCONF distribution.
See the following sections for more information:
Providing Method Options or Attributes
Many Perl methods have one or more options or attributes. The
following list describes the notation used to define a method's options
in the lib/Net/Netconf/Plugins.pm and lib/Net/Netconf/release/package_methods.pl files, and the notation that an application
uses when invoking the method:
- A method without options is defined as $NO_ARGS, as in the following entry for the get_autoinstallation_status_information method:
## Method : get-autoinstallation-status-information ## Returns: autoinstallation-status-information ## Command: "show system autoinstallation status" get_autoinstallation_status_information => $NO_ARGS,
To invoke a method without options, follow the method name with an empty set of parentheses as in the following example:
$jnx->get_autoinstallation_status_information( );
- A fixed-form option is defined as type $TOGGLE. In the following example, the get_software_information method takes two fixed-form options, brief and detail:
## Method : <get-ancp-neighbor-information> ## Returns: <ancp-neighbor-information> ## Command: "show ancp neighbor" get_ancp_neighbor_information => { brief => $TOGGLE, detail => $TOGGLE, }To include a fixed-form option when invoking a method, set it to the value 1 (one) as in the following example:
$jnx->get-ancp-neighbor-information(brief => 1);
- 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:
## Method : <get-passive-monitoring-usage-information> ## Returns: <passive-monitoring-usage-information> ## Command: "show passive-monitoring usage" get_passive_monitoring_usage_information => { interface_name => $STRING, }To include a variable value when invoking a method, enclose the value in single quotes as in the following example:
$jnx->get_cos_drop_profile_information(profile_name => 'user-drop-profile');
- 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):
'get_config' => { 'source' => $DOM_STRING, 'source_url' => $URL_STRING, 'filter' => $DOM },A DOM object is XML code:
my $xml_string = " <filter type=\"subtree\"> <configuration> <protocols> <bgp></bgp> </protocols> </configuration> </filter> "; my %queryargs = ( 'source' => "running", 'filter' => $xml_string, );This generates an RPC request:
<rpc message-id='1'> <get-config> <source> <running/> </source> <filter type="subtree"> <configuration> <protocols> <bgp></bgp> </protocols> </configuration> </filter> </get-config></rpc>
A method can have a combination of fixed-form options, options with variable values, attributes, 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 is the recommended way to send a request to the NETCONF server and shows how to handle error conditions. The $jnx variable is defined to be a NET::Netconf::Manager object.
my $res; # Netconf server response
# connect to the Netconf server
my $jnx = new Net::Netconf::Manager(%deviceinfo);
unless (ref $jnx) {
croak "ERROR: $deviceinfo{hostname}: failed to connect.\n";
}
# Lock the configuration database before making any changes
print "Locking configuration database ...\n";
my %queryargs = ( 'target' => 'candidate' );
$res = $jnx->lock_config(%queryargs);
# See if you got an error
if ($jnx->has_error) {
print "ERROR: in processing request \n $jnx->{'request'} \n";
graceful_shutdown($jnx, STATE_CONNECTED, REPORT_FAILURE);
}
# Load the configuration from the given XML file
print "Loading configuration from $xmlfile \n";
if (! -f $xmlfile) {
print "ERROR: Cannot load configuration in $xmlfile\n";
graceful_shutdown($jnx, STATE_LOCKED, REPORT_FAILURE);
}
# Read in the XML file
my $config = read_xml_file($xmlfile);
print "\n\n$config \n\n";
%queryargs = (
'target' => 'candidate',
'config' => $config
);
$res = $jnx->edit_config(%queryargs);
# See if you got an error
if ($jnx->has_error) {
print "ERROR: in processing request \n $jnx->{'request'} \n";
# Get the error
my $error = $jnx->get_first_error();
get_error_info(%$error);
# Disconnect
graceful_shutdown($jnx, STATE_LOCKED, REPORT_FAILURE);
}
# Commit the changes
print "Committing the edit-config changes ...\n";
$jnx->commit();
if ($jnx->has_error) {
print "ERROR: Failed to commit the configuration.\n";
graceful_shutdown($jnx, STATE_CONFIG_LOADED, REPORT_FAILURE);
}
# Unlock the configuration database and
# disconnect from the Netconf server
print "Disconnecting from the Netconf server ...\n";
graceful_shutdown($jnx, STATE_LOCKED, REPORT_SUCCESS);