Commit b791b121 authored by Robert Ricci's avatar Robert Ricci

New script: if2port - Find switch port(s) for a node's interface(s).

Usage: if2port <node | node:if | node if>
Example:
<ricci@paper:~>./if2port tbpc01
+--------+-----+--------+-----+-----+
|node_id1|card1|node_id2|card2|port2|
+--------+-----+--------+-----+-----+
|tbpc01  |    0|cisco   |    3|   25|
|tbpc01  |    1|cisco   |    3|   27|
|tbpc01  |    2|cisco   |    3|   29|
|tbpc01  |    3|cisco   |    3|   31|
|tbpc01  |    4|cisco2  |    3|    1|
+--------+-----+--------+-----+-----+
5 rows processed

<ricci@paper:~>./if2port tbpc01:0
+--------+-----+--------+-----+-----+
|node_id1|card1|node_id2|card2|port2|
+--------+-----+--------+-----+-----+
|tbpc01  |    0|cisco   |    3|   25|
+--------+-----+--------+-----+-----+
1 row processed

<ricci@paper:~>
parent 0a25f312
......@@ -9,7 +9,7 @@ SUBDIR = db
include $(OBJDIR)/Makeconf
BIN_SCRIPTS = mac2if nalloc nfree nodeip
SBIN_SCRIPTS = avail inuse showgraph
SBIN_SCRIPTS = avail inuse showgraph if2port
LIBEXEC_SCRIPTS = ptopgen
#
......
#!/usr/local/bin/perl -w
use Mysql;
use strict;
my $debug = 0;
my ($node, $card);
my $tbdb = "@TBDBNAME@";
if (@ARGV == 2) {
($node,$card) = @ARGV;
} elsif (@ARGV == 1) {
($node,$card) = split /:/,$ARGV[0];
} else {
exit &usage;
}
&debug("Node is $node");
&debug("Card is $card") if (defined $card);
my $dbh = Mysql->connect("localhost",$tbdb,"script","none");
die "Unable to connect to database" unless $dbh;
my $query = qq|SELECT node_id1,card1,node_id2,card2,port2 FROM | .
qq|wires WHERE node_id1="$node"|;
if (defined $card) {
$query .= qq|AND card1="$card"|;
}
&debug("Sending query $query\n");
my $qh = $dbh->query($query);
print $qh->as_string();
sub debug { warn @_,"\n" if $debug; }
sub usage {
print "Usage: $0 <node | node:if | node if>\n";
return -1;
}
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