Commit 59ae8faa authored by Keith Sklower's avatar Keith Sklower

add --vlan_tag option to snmpit (for use with dragon signaling)

handle quieting backends in a different way - (to minimized changes
to nortel, foundry, and hp support), use perl "select" with one arg
to change default for "print" with no explicit fileglob.

print STDERR, STDOUT, still works; won't interfere with tblog() and friends.
will put parallization mods in a separate CVS change.
parent 1e4f5fcc
......@@ -148,7 +148,7 @@ Getopt::Long::Configure("no_ignore_case");
GetOptions(\%opt,
'a','c','d','e','b','B=s@','g','h','i=s@','l+','m=s@','M','n',
'N=s@','o=s@','p=s','q','r','s', 'S=s@','t','E=s','T=s','u=s','U','v=s','w',
'y=s','x=s','z=s','F','L=s','O', 'D', 'R', 'f', 'X');
'y=s','x=s','z=s','F','L=s','O', 'D', 'R', 'f', 'X', 'vlan_tag=i');
# Unused: f,j
if ($opt{h}) {
......@@ -162,6 +162,11 @@ if ($opt{v}) {
if ($opt{q}) {
$quiet = 1;
if ($opt{m} || $opt{o} || $opt{t} || $opt{r} || $opt{X} || $opt{T} ||
$opt{E} || $opt{U} || $opt{u} || $opt{d} || $opt{p} || $opt{e}) {
my $nulldev = open(">>/dev/null");
select $nulldev; # supresses print foo(); without explicit fileglob
}
}
#
......@@ -174,6 +179,7 @@ my @ports;
my @optvlanids = ();
my $equaltrunking = 0;
my $this_user;
our $next_vlan_tag; # XXX see doMakeVlan for explanation
#
# Verify user and get his DB uid for later.
......@@ -758,9 +764,7 @@ COMMAND: foreach my $command (@commands) {
SWITCH: for ($stack_type) {
(/cisco/ || /catalyst/) && do {
require snmpit_cisco_stack;
$stack = new snmpit_cisco_stack($stack_id,$debug,$quiet,
$single_domain,
@{$stacks{$stack_id}});
$stack = new snmpit_cisco_stack($stack_id,$debug,$single_domain, @{$stacks{$stack_id}});
last;
}; # /cisco/
/intel/ && do {
......@@ -771,7 +775,7 @@ COMMAND: foreach my $command (@commands) {
};
/generic/ && do {
require snmpit_stack;
$stack = new snmpit_stack($stack_id,$debug,$quiet,
$stack = new snmpit_stack($stack_id,$debug,
@{$stacks{$stack_id}});
last;
}; # /generic/
......@@ -2005,10 +2009,32 @@ sub doMakeVlan($$@) {
}
}
#
# special temporary case for using a specific vlan number
# will go away when tags are allocated from the database.
#
if ($next_vlan_tag = $opt{'vlan_tag'}) {
my %vlans = $stack->findVlans();
my $number = $vlans{$vlan_name};
if (defined($number)) {
if ($number != $next_vlan_tag) {
bad: print "VLAN $vlan_name already has vlan_tag $number\n";
return 1;
}
goto old_number;
} else {
while (my ($id, $tag) = each %vlans) {
if ($tag == $next_vlan_tag)
{ $vlan_name = $id; $number = $tag; goto bad; }
}
goto new_number;
}
}
#
# Create it if it doesn't already exist
#
if ($stack->vlanExists($vlan_id)) {
old_number:
print "VLAN $vlan_name already exists\n"
if (!$quiet);
......@@ -2026,6 +2052,7 @@ sub doMakeVlan($$@) {
$errors += $perrors;
}
} else {
new_number:
print "Creating VLAN $vlan_name ...\n"
if (!$quiet);
my $vlan_number = $stack->createVlan($vlan_id,\@ports,@pvlanArgs);
......
......@@ -62,7 +62,7 @@ my $PORT_FORMAT_NODEPORT = 3;
# usage: new($classname,$devicename,$debuglevel,$community)
# returns a new object, blessed into the snmpit_cisco class.
#
sub new($$$$;$) {
sub new($$$;$) {
# The next two lines are some voodoo taken from perltoot(1)
my $proto = shift;
......@@ -70,7 +70,6 @@ sub new($$$$;$) {
my $name = shift;
my $debugLevel = shift;
my $quiet = shift;
my $community = shift;
#
......@@ -86,11 +85,6 @@ sub new($$$$;$) {
} else {
$self->{DEBUG} = 0;
}
if (defined($quiet)) {
$self->{QUIET} = $quiet;
} else {
$self->{QUIET} = 0;
}
$self->{BLOCK} = 1;
$self->{BULK} = 1;
$self->{NAME} = $name;
......@@ -509,8 +503,7 @@ sub vlanUnlock($) {
my $EditOp = 'vtpVlanEditOperation'; # use index 1
my $ApplyStatus = 'vtpVlanApplyStatus'; # use index 1
print " Applying VLAN changes on $self->{NAME} ..."
if (! $self->{QUIET});
print " Applying VLAN changes on $self->{NAME} ...";
#
# Send the command to apply what's in the edit buffer
......@@ -552,13 +545,11 @@ sub vlanUnlock($) {
# Tell the caller what happened
#
if ($ApplyRetVal ne "succeeded") {
print " FAILED\n"
if (! $self->{QUIET});
print " FAILED\n";
warn("**** ERROR: Failure applying VLAN changes on $self->{NAME}:".
" $ApplyRetVal\n");
} else {
print " Succeeded\n"
if (! $self->{QUIET});
print " Succeeded\n";
$self->debug("Apply Succeeded.\n");
}
}
......@@ -802,7 +793,7 @@ sub createVlan($$;$$$) {
my $SAID = pack("H*",sprintf("%08x",$vlan_number + 100000));
print " Creating VLAN $vlan_id as VLAN #$vlan_number on " .
"$self->{NAME} ... " if (! $self->{QUIET});
"$self->{NAME} ... ";
#
# Perform the actual creation. Yes, this next line MUST happen all in
......@@ -816,7 +807,7 @@ sub createVlan($$;$$$) {
my @varList = ($vlan_number > 1000) ? ($statusRow, $nameRow)
: ($statusRow, $typeRow, $nameRow, $saidRow);
my $RetVal = snmpitSetWarn($self->{SESS}, new SNMP::VarList(@varList));
print "",($RetVal? "Succeeded":"Failed"), ".\n" if (! $self->{QUIET});
print "",($RetVal? "Succeeded":"Failed"), ".\n";
#
# Check for success
......@@ -1258,20 +1249,13 @@ sub removeVlan($@) {
#
my $VlanRowStatus = 'vtpVlanEditRowStatus'; # vlan is index
print " Removing VLAN #$vlan_number on $self->{NAME} ... "
if (! $self->{QUIET});
print " Removing VLAN #$vlan_number on $self->{NAME} ... ";
my $RetVal = snmpitSetWarn($self->{SESS},
[$VlanRowStatus,"1.$vlan_number","destroy","INTEGER"]);
if ($RetVal) {
print "Succeeded.\n" if (! $self->{QUIET});
print "Succeeded.\n";
} else {
if ($self->{QUIET}) {
print " Removing VLAN #$vlan_number on ".
"$self->{NAME} failed.\n";
}
else {
print "Failed.\n";
}
print "Failed.\n";
$errors++;
}
......
......@@ -40,7 +40,6 @@ sub new($$$$$@) {
my $stack_id = shift;
my $debuglevel = shift;
my $quiet = shift;
my $uses_vtp = shift;
my @devicenames = @_;
......@@ -57,12 +56,6 @@ sub new($$$$$@) {
} else {
$self->{DEBUG} = 0;
}
if (defined $quiet) {
$self->{QUIET} = $quiet;
} else {
$self->{QUIET} = 0;
}
#
# The ID of this stack
#
......@@ -424,12 +417,17 @@ sub createVlan($$$;$$$) {
# VLANs or not
#
my $vlan_number;
# XXX temp, see doMakeVlans in snmpit.in
if ($::next_vlan_tag)
{ $vlan_number = $::next_vlan_tag; $::next_vlan_tag = 0; }
if ($self->{VTP} || $self->{PRUNE_VLANS}) {
#
# We just need to create the VLAN on the stack leader
#
#
$vlan_number = $self->{LEADER}->createVlan($vlan_id,undef,@otherargs);
$vlan_number = $self->{LEADER}->createVlan($vlan_id,$vlan_number,@otherargs);
} else {
#
# We need to create the VLAN on all devices
......
......@@ -36,7 +36,6 @@ sub new($$$$@) {
my $stack_id = shift;
my $debuglevel = shift;
my $quiet = shift;
my @devicenames = @_;
#
......@@ -53,11 +52,6 @@ sub new($$$$@) {
} else {
$self->{DEBUG} = 0;
}
if (defined $quiet) {
$self->{QUIET} = $quiet;
} else {
$self->{QUIET} = 0;
}
$self->{STACKID} = $stack_id;
$self->{MAX_VLAN} = 4095;
......@@ -114,8 +108,7 @@ sub new($$$$@) {
SWITCH: for ($type) {
(/cisco/) && do {
use snmpit_cisco;
$device = new snmpit_cisco($devicename,
$self->{DEBUG},$self->{QUIET});
$device = new snmpit_cisco($devicename,$self->{DEBUG});
last;
}; # /cisco/
(/foundry1500/ || /foundry9604/)
......@@ -418,6 +411,9 @@ sub newVlanNumber($$) {
%vlans = $self->findVlans();
}
my $number = $vlans{$vlan_id};
# XXX temp, see doMakeVlans in snmpit.in
if ($::next_vlan_tag)
{$number = $::next_vlan_tag; $::next_vlan_tag = 0; return $number; }
if (defined($number)) { return 0; }
my @numbers = sort values %vlans;
......@@ -461,7 +457,7 @@ sub createVlan($$$;$$$) {
$vlan_number = $self->newVlanNumber($vlan_id);
if ($vlan_number == 0) { last LOCKBLOCK;}
print "Creating VLAN $vlan_id as VLAN #$vlan_number on stack " .
"$self->{STACKID} ... \n" if (! $self->{QUIET});
"$self->{STACKID} ... \n";
if ($self->{ALLVLANSONLEADER}) {
$res = $self->{LEADER}->createVlan($vlan_id, $vlan_number);
$self->unlock();
......@@ -489,16 +485,12 @@ sub createVlan($$$;$$$) {
#
# Ooops, failed. Don't try any more
#
if ($self->{QUIET}) {
print "$errortype VLAN $vlan_id as VLAN #$vlan_number on ".
"stack $self->{STACKID} ... \n";
}
print "Failed\n";
$vlan_number = 0;
last LOCKBLOCK;
}
}
print "Succeeded\n" if (! $self->{QUIET});
print "Succeeded\n";
}
$self->unlock();
......
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