Commit 0d807a22 authored by Leigh Stoller's avatar Leigh Stoller

Add -s option to showvlans to print the set of vlans that are reserved

for stitching, via the external_networks table. For Nick.
parent 30558460
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# Copyright (c) 2007-2013 University of Utah and the Flux Group. # Copyright (c) 2007-2014 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -4002,6 +4002,29 @@ sub Stringify($) ...@@ -4002,6 +4002,29 @@ sub Stringify($)
return "[External Network: $network_id,$node_id]"; return "[External Network: $network_id,$node_id]";
} }
#
# All external networks.
#
sub LookupAll($$)
{
my ($class, $pref) = @_;
my @result = ();
my $query_result =
DBQueryWarn("select network_id from external_networks");
return -1
if (!$query_result);
while (my ($network_id) = $query_result->fetchrow_array()) {
my $network = ExternalNetwork->Lookup($network_id);
return -1
if (!defined($network));
push(@result, $network);
}
@$pref = @result;
return 0;
}
# #
# Given a vlan tag, is it okay (in the range). # Given a vlan tag, is it okay (in the range).
# #
...@@ -4033,5 +4056,18 @@ sub CalculateVlans($) ...@@ -4033,5 +4056,18 @@ sub CalculateVlans($)
} }
} }
# Return the list calculated above.
sub VlanTagList($$)
{
my ($self, $pref) = @_;
my @result = ();
foreach my $tag (keys(%{ $self->{'VLANSET'} })) {
push(@result, $tag);
}
@$pref = @result;
return 0;
}
# _Always_ make sure that this 1 is at the end of the file... # _Always_ make sure that this 1 is at the end of the file...
1; 1;
...@@ -26,14 +26,16 @@ use English; ...@@ -26,14 +26,16 @@ use English;
use Getopt::Std; use Getopt::Std;
# #
# This does none thing; dumps the set of current vlans (in use). # This does one thing; dumps the set of current vlans (in use),
# plus all of the vlans reserved for stitching, since technically
# they aer in use too at most sites.
# #
sub usage() sub usage()
{ {
print(STDERR "Usage: showvlans\n"); print(STDERR "Usage: showvlans [-s]\n");
exit(-1); exit(-1);
} }
my $optlist = "d"; my $optlist = "ds";
my $debug = 0; my $debug = 0;
# #
...@@ -46,6 +48,7 @@ my $TB = "@prefix@"; ...@@ -46,6 +48,7 @@ my $TB = "@prefix@";
# #
use lib "@prefix@/lib"; use lib "@prefix@/lib";
use emdb; use emdb;
use Lan;
# #
# Turn off line buffering on output # Turn off line buffering on output
...@@ -58,9 +61,48 @@ $| = 1; ...@@ -58,9 +61,48 @@ $| = 1;
$ENV{'PATH'} = "/bin:/sbin:/usr/bin:/usr/sbin"; $ENV{'PATH'} = "/bin:/sbin:/usr/bin:/usr/sbin";
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
my $query_result = #
DBQueryFatal("select tag from reserved_vlantags order by tag"); # Parse command arguments. Once we return from getopts, all that should be
while (my ($tag) = $query_result->fetchrow_array()) { # left are the required arguments.
print "$tag\n"; #
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"s"})) {
#
# Stitching vlans, which might not be in use but are still
# considered reserved.
#
my %vlantags = ();
my @networks;
if (ExternalNetwork->LookupAll(\@networks) < 0) {
die("Could not get external network\n");
}
foreach my $network (@networks) {
my @tags;
if ($network->VlanTagList(\@tags) < 0) {
die("Could not get tag list for $network\n");
}
foreach my $tag (@tags) {
$vlantags{"$tag"} = $tag;
}
}
foreach my $tag (sort(keys(%vlantags))) {
print "$tag\n";
}
} }
else {
my $query_result =
DBQueryFatal("select tag from reserved_vlantags order by tag");
while (my ($tag) = $query_result->fetchrow_array()) {
print "$tag\n";
}
}
exit(0); exit(0);
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