Commit 81ca0334 authored by Robert Ricci's avatar Robert Ricci

Add a "leader" column to the switch_stack_types table so that we no longer need

to assume that the leader of a stack is the switch after which it was named -
we can now name stacks things like 'Control' or 'Experiment'.
parent 241132a3
......@@ -1463,6 +1463,7 @@ CREATE TABLE switch_stack_types (
snmp_community varchar(32) default NULL,
min_vlan int(11) default NULL,
max_vlan int(11) default NULL,
leader varchar(32) default NULL,
PRIMARY KEY (stack_id)
) TYPE=MyISAM;
......
......@@ -2208,3 +2208,30 @@ last_net_act,last_cpu_act,last_ext_act);
default '0' after security_level;
alter table experiments add panic_date datetime default NULL \
after paniced;
1.293: Add a "leader" column to the switch_stack_types table so that we no
longer need to assume that the leader of a stack is the switch after
which it was named - we can now name stacks things like 'Control' or
'Experiment'.
alter table switch_stack_types add column leader varchar(32) \
default NULL;
Set the leader names like this:
update switch_stack_types set leader=stack_id;
Then, determine the name of the experimental net stack like so:
select distinct stack_id from nodes as n left join switch_stacks as \
s on n.node_id=s.node_id where n.role='ctrlswitch';
You can then set the name of the experimental stack like this
(substituting in the name of the stack you just found):
update switch_stacks set stack_id='Control' where \
stack_id='<stackid>';
update switch_stack_types set stack_id='Control' where \
stack_id='<stackid>';
Then, do the same with the control net:
......@@ -29,9 +29,6 @@ use libdb;
# so that the object knows which to connect to. A future version may not
# require the device list, and dynamically connect to devices as appropriate
#
# For a Cisco stack, the stack_id happens to also be the name of the stack
# leader.
#
# usage: new(string name, string stack_id, int debuglevel, list of devicenames)
# returns a new object blessed into the snmpit_cisco_stack class
#
......@@ -61,10 +58,20 @@ sub new($$$$@) {
}
#
# The stackid just happens to also be leader of the stack
# The ID of this stack
#
$self->{STACKID} = $stack_id;
#
# The name of the leader of this stack. We fall back on the old behavior of
# using the stack name as the leader if the leader is not set
#
my $leader_name = getStackLeader($stack_id);
if (!$leader_name) {
$leader_name = $stack_id;
}
$self->{LEADERNAME} = $leader_name;
#
# Store the list of devices we're supposed to operate on
#
......@@ -105,7 +112,7 @@ sub new($$$$@) {
die "Failed to create a device object for $devicename\n";
} else {
$self->{DEVICES}{$devicename} = $device;
if ($devicename eq $self->{STACKID}) {
if ($devicename eq $self->{LEADERNAME}) {
$self->{LEADER} = $device;
}
last;
......@@ -122,8 +129,8 @@ sub new($$$$@) {
if (!$self->{LEADER}) {
# XXX: For simplicity, we assume for now that the leader is a Cisco
use snmpit_cisco;
my $type = getDeviceType($self->{STACKID});
$self->{LEADER} = new snmpit_cisco($self->{STACKID}, $self->{DEBUG});
my $type = getDeviceType($self->{LEADERNAME});
$self->{LEADER} = new snmpit_cisco($self->{LEADERNAME}, $self->{DEBUG});
}
bless($self,$class);
......
......@@ -18,7 +18,8 @@ use Exporter;
getVlanPorts
getExperimentVlans getDeviceNames getDeviceType
getInterfaceSettings mapPortsToDevices getSwitchStack
getStackType getDeviceOptions getTrunks getTrunksFromSwitches
getStackType getStackLeader
getDeviceOptions getTrunks getTrunksFromSwitches
getExperimentPorts snmpitGet snmpitGetWarn snmpitGetFatal
snmpitSet snmpitSetWarn snmpitSetFatal snmpitWarn snmpitFatal
printVars tbsort );
......@@ -393,6 +394,23 @@ sub getStackType($) {
}
}
#
# Returns the leader for the given stack - the meaning of this is vendor-
# specific. May be undefined.
#
sub getStackLeader($) {
my $stack = shift;
my $result = DBQueryFatal("SELECT leader FROM switch_stack_types " .
"WHERE stack_id='$stack'");
if (!$result->numrows()) {
print STDERR "No stack found called $stack\n";
return undef;
} else {
my ($leader) = ($result->fetchrow());
return $leader;
}
}
#
# Get a hash that describes the configuration options for a switch. The idea is
# that the device's object will call this method to get some options. Right
......
......@@ -54,13 +54,20 @@ sub new($$$@) {
$self->{DEBUG} = 0;
}
#
# The stackid just happens to also be leader of the stack
#
$self->{STACKID} = $stack_id;
$self->{MAX_VLAN} = 4095;
$self->{MIN_VLAN} = 2;
#
# The name of the leader of this stack. We fall back on the old behavior of
# using the stack name as the leader if the leader is not set
#
my $leader_name = getStackLeader($stack_id);
if (!$leader_name) {
$leader_name = $stack_id;
}
$self->{LEADERNAME} = $leader_name;
#
# Store the list of devices we're supposed to operate on
#
......@@ -104,7 +111,7 @@ sub new($$$@) {
next;
}
$self->{DEVICES}{$devicename} = $device;
if ($devicename eq $self->{STACKID}) {
if ($devicename eq $self->{LEADERNAME}) {
$self->{LEADER} = $device;
}
if (defined($device->{MIN_VLAN}) &&
......
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