Commit 645197be authored by Robert Ricci's avatar Robert Ricci

snmpit now discovers which switch to operate on based on the members of the

VLANs it is to operate on. This is only a temporary multi-switch solution, as
it only picks one switch to operate on.

Also, added a sanity check in snmpit_cisco.pm. Now checks every port that
it controls, to make sure it's on the right switch. If this sanity check
fails, dies to prevent any damage to existing switch configuration.
parent 9be740e3
......@@ -402,7 +402,40 @@ sub ParseArgs {
if ($reset && ((!defined $pid) || (!defined $eid)));
# If everything is okay so far, initialize snmpit_lib
snmpit_lib::init($DBNAME, $debug);
if (!defined($i)||!$i||$i eq "") { $i = "cisco1"; }
if ($t || $reset) {
if ( ! vlanid("$pid:$eid")) {
print "There were no VLANs in the database table for '$pid' '$eid'\n";
exit(0);
} else {
foreach $id ( split(" ",vlanid("$pid:$eid")) ) {
my $members = vlanmemb($id);
$vlantable{$id} = $members;
print "id: $id\t$members\n" if $debug;
foreach $node (split (" ",$members)) {
if (!defined macport($node)) {
die("Invalid node found in VLANs table: '$node'\n");
}
}
}
}
}
if (!defined($i)||!$i||$i eq "") {
if ($t || $reset) {
# When creating and deleteing VLANs, we look at a random node to
# figure out which switch to contact. XXX: This does NOT work
# for experiments using multiple switches
my $nodes = $vlantable{(keys %vlantable)[0]};
my $node = (split(" ",$nodes))[0];
my $switch = (split(":",portnum($node)))[0];
print "Using switch $switch\n";
$i = $switch;
} else {
# In other modes, we default to cisco1
$i = "cisco1";
}
}
if ( defined Dev($i) ) {
if (! ($i =~ /[a-zA-Z]/) ) { $i = Dev($i); } # i is now name
print "Found device $i (",Dev($i),")..." if $debug;
......@@ -483,23 +516,6 @@ sub ParseArgs {
}
$num++;
}
if ($t || $reset) {
if ( ! vlanid("$pid:$eid")) {
print "There were no VLANs in the database table for '$pid' '$eid'\n";
exit(0);
} else {
foreach $id ( split(" ",vlanid("$pid:$eid")) ) {
my $members = vlanmemb($id);
$vlantable{$id} = $members;
print "id: $id\t$members\n" if $debug;
foreach $node (split (" ",$members)) {
if (!defined macport($node)) {
die("Invalid node found in VLANs table: '$node'\n");
}
}
}
}
}
if ($powerop) {
$num=0;
while(@outlets != 0 && $num < @outlets) {
......
......@@ -79,7 +79,17 @@ sub portControl {
my @p = map {
if ( /^([^-]*)-\d:(.*)$/ ) { $_ = "$1:$2"; }
my $pnum = portnum($_);
my $port = (split(":",$pnum))[1];
my ($switch, $port) = split(":",$pnum);
print "Sanity check: $switch, $ip\n" if $debug;
# Sanity check: Make sure the port we're supposed to be controlling is on
# this switch
if (($switch ne $ip) && (Dev($switch) ne $ip)) {
# Need to remeber to release the VLAN lock
&vlanUnlock();
die "Sanity check failed got port on $switch while working on $ip\n";
}
my $i = $ifIndex{$port};
print "$_ -> $port -> $i\n" if $debug;
if ($cmd =~/able/) { $i; } else { $port }
......
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