Name

lib_nmstools — Library for NMSTOOLS common functions

Synopsis

require '%%NMSTOOLS_HOME%%/lib/lib_nmstools.pl';

nms_readconfig( "devlogin" );

my $nodelist = $nms_config{'env'}{'DATA'} . '/atm/nodelist';
$hostname .= '.' . $nms_config{'devlogin'}{'DEVDOMAINNAME'};

nms_enumnodes( $nodelistfile, \&callback );

my $telnet = nms_opentelnet( $hostname );
	
if( $telnet )
{
    print $telnet "show version\r";
    print $telnet "exit\r";
    $telnet->close();
}
else
{
    print STDERR "Cannot connect to $hostname";
}

my $namestring = nms_interfaceref( $hostname, $interface );

Description

These library routines are used for establishing the telnet connections to the network devices.

%nms_config

Configuration options initialized by nms_readconfig(). It's a two-dimensional hash array, with the first hash pointing to the configuration filename, and the second hash referencing the configuration options. Also the NMSTOOLS environment variables are initialized into the array as follows:

$nms_config{'env'}{'HOME'}
$nms_config{'env'}{'DATA'}
$nms_config{'env'}{'HTML'}

nms_readconfig( $configname );
Accesses the file named $NMSTOOLS_HOME/etc/configname.conf and reads the configuration lines of form OPTION = VALUE, one per line. The results are put into the hash array $nms_config{'configname'}{'OPTION'}.

nms_enumnodes( $nodelistfile, \&callback );
Reads the node names from specified file, one per line, performs telnet connection to each node, and after that calls the callback function with three arguments: &$callback($telnet, $node, $hostname);, where $telnet is the Expect.pm handle, $node is the node name, and $hostname is the fully-qualified domain name of the host being connected.

nms_opentelnet( $hostname );
Opens a telnet session to the specified hostname, and performs login and enable mode. Then the Expect.pm handle is returned.

nms_interfaceref( $hostname, $interface );
Returns the string formed from the specified hostname and interface, with all special characters replaced by underscore. The string returned is suitable for file name composition.