Commit a451a317 authored by Robert Ricci's avatar Robert Ricci

Add functions to snmpit_lib to convert from port:iface format to

port:card.

Call this every place (I think I got them all) a port list is used in
snmpit.
parent 9946fd2b
......@@ -232,7 +232,7 @@ if ($opt{B}) {
die "ERROR: No port given in status string\n";
}
if ($args{port}) {
push @ports, $args{port};
push @ports, convertPortsFromIfaces($args{port});
}
}
}
......@@ -361,6 +361,11 @@ if ($pid && $eid) {
# access to the nodes that the ports are on
#
# Convert ports into the correct format
if (@ports) {
@ports = convertPortsFromIfaces(@ports);
}
if (@ports) {
#
# Allow ports to be given in one of two forms: node:port, or switch.port.
......@@ -480,7 +485,7 @@ foreach my $command (@commands) {
if (!$args{port}) {
die "ERROR: No port given in status string\n";
}
@ports = ($args{port});
@ports = convertPortsFromIfaces($args{port});
if ($args{vlan}) {
@vlans = ($args{vlan});
}
......
......@@ -15,7 +15,7 @@ use Exporter;
@ISA = ("Exporter");
@EXPORT = qw( macport portnum Dev vlanmemb vlanid
getTestSwitches getControlSwitches getSwitchesInStack
getVlanPorts
getVlanPorts convertPortsFromIfaces convertPortFromIface
getExperimentVlans getDeviceNames getDeviceType
getInterfaceSettings mapPortsToDevices getSwitchPrimaryStack
getSwitchStacks
......@@ -156,28 +156,50 @@ sub getVlanPorts (@) {
my $members = $row[0];
# $members is a space-seprated list
foreach my $port (split /\s+/,$members) {
# Due to the inconsistent nature of our tables (curses!), we
# have to do some conversion here
$port =~ /^(.+):(.+)/;
my ($node,$iface) = ($1,$2);
if (!defined($node) || !defined($iface)) {
warn "WARNING: Bad node in VLAN: $port - skipping\n";
next;
}
my $result = DBQueryFatal("SELECT card FROM interfaces " .
"WHERE node_id='$node' AND iface='$iface'");
if (!$result->num_rows()) {
warn "WARNING: Bad node/iface pair in VLAN: $port - skipping\n";
next;
}
push @ports, $port;
}
}
my $card = ($result->fetchrow())[0];
# Convert from the DB format to the one used by the snmpit modules
return convertPortsFromIfaces(@ports);
}
# OK, finally have the info we need
push @ports, $node . ":" . $card;
}
#
# Convert an entire list of ports in port:iface format to into port:card -
# returns other port forms unchanged.
#
sub convertPortsFromIfaces(@) {
my @ports = @_;
return map {
if (/(.+):([A-Za-z].*)/) {
# Seems to be a node:iface line
convertPortFromIface($_);
} else {
$_;
}
} @ports;
}
#
# Convert a port in port:iface format to port:card
#
sub convertPortFromIface($) {
my ($port) = $_;
if ($port =~ /(.+):(.+)/) {
my ($node,$iface) = ($1,$2);
my $result = DBQueryFatal("SELECT card FROM interfaces " .
"WHERE node_id='$node' AND iface='$iface'");
if (!$result->num_rows()) {
warn "WARNING: convertPortFromIface($port) - Unable to get card\n";
return $port;
}
my $card = ($result->fetchrow())[0];
return "$node:$card";
} else {
warn "WARNING: convertPortFromIface($port) - Bad port format\n";
return $port;
}
return @ports;
}
#
......
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