Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requesting for some NETCONF PHP Toolkit sample code. #1

Open
tarikuli opened this issue Dec 9, 2013 · 1 comment
Open

Requesting for some NETCONF PHP Toolkit sample code. #1

tarikuli opened this issue Dec 9, 2013 · 1 comment

Comments

@tarikuli
Copy link

tarikuli commented Dec 9, 2013

Hi ankitjain093,
Thank you very much for your great contribution. Your junOS " NETCONF PHP API" (https://github.com/ankitjain093/netconf-php) great help me.

Would you please share sample complete php code like,

  1. Establishes a connection to the NETCONF server on the routing platform.
  2. Opens a NETCONF session, as described in Starting the NETCONF Session.
  3. Locks the candidate configuration
  4. Requests operational or configuration information, or changes configuration information.
  5. Verifies the syntactic correctness of a configuration before attempting to commit it.
  6. Commits changes made to the configuration, as described in Committing a Configuration.
  7. Unlocks the candidate configuration.
  8. Ends the NETCONF session and closes the connection to the device.

I do not found any example source code how call your netconf-php api and how pass argument. I will be very glad to you for sharing a complete demo. My email address [email protected]

@tarikuli
Copy link
Author

tarikuli commented Dec 9, 2013

Hi ankitjain093,
Here is a sample code of Perl language. Please give us PHP language code like this.

my %deviceinfo = (
'access' => $access,
'login' => $login,
'password' => $password,
'hostname' => $hostname,

);

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant