Commit 84e1a9c0 authored by Mac Newbold's avatar Mac Newbold

Changes to make savevlans possible in every tbrun/tbend.

Added savevlans to be configured, fixed installation as suid root program.
Added calls to savevlans in tbrun/tbend.
parent e6d914ac
......@@ -100,7 +100,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
tbsetup/ir/GNUmakefile tbsetup/ir/postassign tbsetup/snmpit \
tbsetup/ir/assign_wrapper tbsetup/ns2ir/GNUmakefile \
tbsetup/ns2ir/postparse tbsetup/ir/handle_os tbsetup/ir/handle_ip \
tbsetup/ns2ir/parse.tcl \
tbsetup/ns2ir/parse.tcl tbsetup/savevlans \
tbsetup/tbprerun tbsetup/tbrun tbsetup/tbend tbsetup/tbreport \
tbsetup/checkpass/GNUmakefile \
tip/GNUmakefile \
......
......@@ -11,9 +11,9 @@ include $(OBJDIR)/Makeconf
SUBDIRS = checkpass ir ns2ir
BIN_STUFF = power snmpit tbend tbrun tbprerun tbreport \
vpower vsnmpit os_load
vpower vsnmpit os_load savevlans
SBIN_STUFF = resetvlans savevlans console_setup.proxy sched_reload
SBIN_STUFF = resetvlans console_setup.proxy sched_reload
LIBEXEC_STUFF = mkprojdir rmproj mkacct-ctrl rmacct-ctrl \
os_setup mkexpdir tbdoit tbstopit console_setup
......@@ -69,6 +69,8 @@ post-install:
chmod u+s $(INSTALL_LIBEXECDIR)/os_setup
chown root $(INSTALL_BINDIR)/os_load
chmod u+s $(INSTALL_BINDIR)/os_load
chown root $(INSTALL_BINDIR)/savevlans
chmod u+s $(INSTALL_BINDIR)/savevlans
chown root $(INSTALL_LIBEXECDIR)/console_setup
chmod u+s $(INSTALL_LIBEXECDIR)/console_setup
......
#!/usr/local/bin/perl -w
#
# savevlans - Saves vlans from the switches into a .ir file, suitable for
# restoring with 'snmpit -f <file>'.
#
open(LIST,"snmpit -l |");
print "START vlan\n";
while(<LIST>) {
chop;
if (/(^ID)|(^--)/) { next; }
s/[\t ]+/ /g;
/(\d+)\s+(\S+)\s+(.*)/;
if ($2 ne "System") {
(my $name, my @IDs) = ($2,split(" ",$3));
print "$name @IDs\n";
}
}
print "END vlan\n";
#!/usr/local/bin/perl -wT
#
# savevlans - Saves vlans from the switches into a .ir file, suitable for
# restoring with 'snmpit -f <file>'.
#
my $TBROOT = "@prefix@";
$ENV{'PATH'} = '@prefix@/sbin:@prefix@/bin:/bin';
open(LIST,"snmpit -l |") || die ("savevlans: couldn't run snmpit: $!\n");
my $time = `date +20%y%m%d-%H.%M.%S`;
chomp ($time);
my $name = "$TBROOT/backup/vlans-$time";
$name =~ /^([a-zA-Z\/_\-0-9:\.\'\"]*).*$/;
$name = $1;
print "Saving VLAN configuration to '$name'\n";
use Fcntl;
sysopen(OUT, $name, (O_WRONLY | O_EXCL | O_CREAT) ) ||
die ("savevlans: couldn't open '$name' for writing: $!\n");
print OUT "START vlan\n";
while(<LIST>) {
chop;
if (/(^ID)|(^--)|(^1 )/) { next; }
s/[\t ]+/ /g;
/(\d+)\s+(\S+)\s+(.*)/;
if ($2 ne "System") {
(my $name, my @IDs) = ($2,split(" ",$3));
print OUT "$name @IDs\n";
}
}
print OUT "END vlan\n";
close(LIST);
close(OUT);
chmod( 0444, $name);
......@@ -308,7 +308,7 @@ sub GetToken {
$tries = 10;
} else {
print STDERR time,
"Try #$tries - Result is $RetVal - Waiting 2 seconds\n";
"Try #$tries - Result is $RetVal - Waiting 2 seconds\n" if $debug;
select (undef, undef, undef, 2); #wait 2 seconds
}
}
......
......@@ -51,6 +51,11 @@ if (&tbs_exec("resetvlans " . join(" ",@nodes))) {
exit(1);
}
&tbs_out("Backing up VLAN configuration\n");
if (&tbs_exec("savevlans")) {
&tbs_out("WARNING: Failed to back up VLAN configuration\n");
}
&tbs_out("Freeing resources\n");
if (&tbs_exec("nfree $pid $eid")) {
&tbs_out("Failed to free resources.\n");
......
......@@ -46,6 +46,11 @@ if (&tbs_exec("snmpit -u -f $irfile")) {
exit(1);
}
&tbs_out("Backing up VLAN configuration\n");
if (&tbs_exec("savevlans")) {
&tbs_out("WARNING: Failed to back up VLAN configuration\n");
}
&tbs_out("Resetting OS and rebooting.\n");
if (&tbs_exec("os_setup $pid $eid $irfile")) {
&tbs_out("Failed to reset OS and reboot nodes.\n");
......
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