Commit 8bf81708 authored by Kirk Webb's avatar Kirk Webb

Netconf-over-ssh library for snmpit.

I don't know what I like most about this module, working with Expect or
handling XML namespaces... Includes the basics of the Netconf protocol.
Only tested with HP Netconf-over-ssh (Comware)!

Main interface calls:

$ncobj = snmpit_libNetconf->new($switch, $userpass, $port, $debuglvl)

Create a new Netconf library object, pointed at switch host $switch.
Username with optional password are passed as second argument (delimit
with ':'). $port is port to connect to, and $debuglvl is the debugging
level. Last two arguments are optional.

$ncobj->doGet($filter)

Execute Netconf "Get", with optional Netconf XML filter argument.

$ncobj->doGetConfig($filter, $source)

Get entire switch config, or partial config if $filter is supplied.
$source is which config (running or saved).  Arguments are optional.

$ncobj->doEditConfig($xmlconf, $target, $defop);

Edit the switch's config.  $xmlconf is an XML::LibXML::Node object
containing the XML-encoded configuration update. $target identifies what
to apply it to (running or startup. Defaults to running). $defop is the
default operation (merge, replace, none. Defaults to "merge").  Last two
arguments are optional.

$ncobj->doRPC($cmd, $xmlarg)

Generic RPC dispatcher (Used by the other "do" commands above).  $cmd is
the rpc command to execute. Optional $xmlarg parameter is an
XML:LibXML::Node object that encodes the arguments to $cmd.
parent d2aec70d
This diff is collapsed.
#!/usr/bin/perl -w
use snmpit_libNetconf;
use XML::LibXML;
if (@ARGV < 3) {
print "Usage: $0 <switch_host> <username[:pass]> <netconf-command> <XML-args>";
exit 1;
}
my ($switch, $user, $cmd, $xmlarg) = @ARGV;
my $parser = XML::LibXML->new();
my $argnode;
if ($xmlarg) {
$argnode = eval { $parser->parse_balanced_chunk($xmlarg) };
if ($@) {
print "Error parsing XML argument: $@\n";
exit 1;
}
}
my $ncconn = snmpit_libNetconf->new($switch, $user);
#$ncconn->debug(1);
if (!$ncconn) {
print "Could not create new Netconf object for $switch!\n";
exit 1;
}
my $res;
SWITCH: for ($cmd) {
/^get$/ && do {
$res = $ncconn->doGet($argnode);
last SWITCH;
};
/^get-config$/ && do {
$res = $ncconn->doGetConfig($argnode);
last SWITCH;
};
/^edit-config$/ && do {
$res = $ncconn->doEditConfig($argnode);
last SWITCH;
};
# default
$res = $ncconn->doRPC($cmd, $argnode);
}
if ($res && $res->[0] eq 2) {
print $res->[1]->toString() ."\n";
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment