Commit dd1d7deb authored by Leigh B Stoller's avatar Leigh B Stoller
Browse files

Merge branch 'master' into snmpit-mle

parents 4a12f575 7f186841
......@@ -2672,6 +2672,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
backend/editnodetype backend/editsitevars backend/newimageid \
backend/editgroup backend/newimageid_ez \
tbsetup/GNUmakefile tbsetup/console_setup tbsetup/spewlogfile \
tbsetup/snmpit_test/GNUmakefile \
tbsetup/spewrpmtar tbsetup/gentopofile tbsetup/power_sgmote.pm \
tbsetup/console_reset tbsetup/bwconfig tbsetup/power_rpc27.pm \
tbsetup/power_mail.pm tbsetup/power_whol.pm \
......
......@@ -903,6 +903,7 @@ outfiles="$outfiles Makeconf GNUmakefile \
backend/editnodetype backend/editsitevars backend/newimageid \
backend/editgroup backend/newimageid_ez \
tbsetup/GNUmakefile tbsetup/console_setup tbsetup/spewlogfile \
tbsetup/snmpit_test/GNUmakefile \
tbsetup/spewrpmtar tbsetup/gentopofile tbsetup/power_sgmote.pm \
tbsetup/console_reset tbsetup/bwconfig tbsetup/power_rpc27.pm \
tbsetup/power_mail.pm tbsetup/power_whol.pm \
......
......@@ -1825,9 +1825,12 @@ sub StartEvents()
print STDERR "Caught a USR2 in child\n";
# Only STDERR can be redirected to the newfile. STDOUT is writing
# to the parent process.
close(STDERR);
open(STDERR, ">> $LOGFILE") or fatal("reopening $LOGFILE: $!");
select STDERR;
$OUTPUT_AUTOFLUSH = 1;
# restore default output.
select STDOUT;
print STDERR "Opened new logfile in child\n";
};
......
#
# Remove stated from syslog.conf, since we no longer use syslog.
# It holds open the log file when it is rolled.
#
use strict;
use libinstall;
my $SYSLOG_CONF = "/etc/syslog.conf";
sub InstallUpdate($$)
{
my ($version, $phase) = @_;
#
# If something should run in the pre-install phase.
#
if ($phase eq "pre") {
Phase "stated", "Updating stated logging", sub {
Phase "syslog.conf", "Updating $SYSLOG_CONF", sub {
PhaseSkip("Already updated")
if !`grep 'stated' $SYSLOG_CONF`;
BackUpFileFatal($SYSLOG_CONF);
ExecQuietFatal("sed -i .orig -e '/stated/d' $SYSLOG_CONF");
};
Phase "syslogd", "Restarting syslogd", sub {
HUPDaemon("syslog");
};
};
}
#
# If something should run in the post-install phase.
#
if ($phase eq "post") {
}
return 0;
}
1;
......@@ -16,7 +16,7 @@ SYSTEM := $(shell uname -s)
include $(OBJDIR)/Makeconf
SUBDIRS = checkpass ns2ir nseparse checkup template_cvsroot
SUBDIRS = checkpass ns2ir nseparse checkup template_cvsroot snmpit_test
ifeq ($(NSVERIFY),1)
SUBDIRS += nsverify
endif
......
......@@ -2269,10 +2269,13 @@ sub _LoadDefaultImages($$)
{
return 0;
}
sub _LoadCurrentImages($$)
{
return 0;
}
#
# But we *do* want the user to be able to simply reload the current OS.
#
#sub _LoadCurrentImages($$)
#{
# return 0;
#}
sub SetupReload($$)
{
......
......@@ -1341,6 +1341,14 @@ sub generateConfig($$) {
};
my @cnetlines = ();
#
# We *HAVE* to remove anything that might have snuck into vlan 1
# in the control net subnet, before trying to assign one in vlan 999.
# This seems to sometimes happen via DHCP...
#
push @cnetlines, "vlan 1";
push @cnetlines, " no ip address";
push @cnetlines, "exit";
if (defined($cnetport) && $cnetport ne '') {
push @cnetlines, "vlan 999";
push @cnetlines, " name \"EmulabControlPort\"";
......@@ -1374,6 +1382,25 @@ sub generateConfig($$) {
}
}
my $community = "private";
my $qres = DBQueryFatal("select sst.snmp_community" .
" from switch_stacks as ss" .
" left join switch_stack_types as sst" .
" on ss.stack_id=sst.stack_id" .
" where ss.node_id='$node_id'");
if (defined($qres) && $qres->numrows()) {
my @row = $qres->fetchrow_array();
if (!defined($row[0])) {
tbwarn "Could not find snmp_community for experiment switch $node_id, using default of '$community'!\n";
}
else {
$community = $row[0];
}
}
else {
tbwarn "Could not find snmp_community for experiment switch $node_id!\n";
}
my @config = (
"hostname \"" . $node_id . "\"",
@cnetlines,
......@@ -1383,6 +1410,10 @@ sub generateConfig($$) {
"aaa authentication ssh login local",
@keylines,
@passwdlines,
'snmp-server community "' . $community . '" Unrestricted',
'snmp-server contact "testbed-ops@flux.utah.edu"',
# try to cover our hind ends and eliminate loops!
"spanning-tree",
"no web-management",
"no telnet-server",
"tftp client",
......
......@@ -476,7 +476,7 @@ if ($pid && $eid) {
#
# See if we use the alternate version of snmpit from Rob.
#
if ($MAINSITE && $TB eq "/usr/testbed" && !$opt{Z}) {
if ($TB eq "/usr/testbed" && !$opt{Z}) {
my $group = (defined($experiment) ? $experiment->GetGroup() : undef);
$EmulabFeatures::verbose = 0;
my $robsnmpit =
......
......@@ -12,27 +12,28 @@
#
# Configure variables
#
use lib '@prefix@/lib';
my $TESTMODE = @TESTMODE@;
my $ELABINELAB = @ELABINELAB@;
my $NOSTACKMIB = @NOSTACKMIB@;
my $MAINSITE = @TBMAINSITE@;
my $TB = '@prefix@';
use lib '@prefix@/lib';
use libdb;
use User;
use Experiment;
use snmpit_lib;
use snmpit_remote;
use libtblog;
use EmulabFeatures;
use Lan;
use English;
use Getopt::Long;
use strict;
# Alternate version of libraries.
use lib '@prefix@/lib/snmpit_test';
use snmpit_lib;
use snmpit_remote;
# Protos
sub parseStatusString($);
sub debug($);
......@@ -2799,9 +2800,10 @@ sub doSyncVlansWithDB($) {
if (!@dbports) {
print " Making it consistent\n";
foreach my $port (@swports) {
# Flip back to node:card for next call
$port = portiface($port);
if ($vlan->AddPort($port)) {
print "Could not add $port to $vlan\n";
$errors++;
}
}
VLan->RecordVlanInsertion($vlan->id(), $stackid);
......
......@@ -18,7 +18,6 @@ use Exporter;
# Must come after package declaration!
use lib '@prefix@/lib';
use English;
use libdb;
use libtestbed;
......
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
# All rights reserved.
#
SRCDIR = @srcdir@
TESTBED_SRCDIR = @top_srcdir@
OBJDIR = ../..
SUBDIR = tbsetup/snmpit_test
ISMAINSITE = @TBMAINSITE@
SYSTEM := $(shell uname -s)
include $(OBJDIR)/Makeconf
SUBDIRS =
LIB_STUFF = snmpit_intel.pm \
snmpit_cisco.pm snmpit_lib.pm snmpit_apc.pm \
snmpit_cisco_stack.pm snmpit_intel_stack.pm \
snmpit_foundry.pm snmpit_stack.pm snmpit_remote.pm \
snmpit_nortel.pm snmpit_hp.pm snmpit_apcon.pm
#
# Force dependencies on the scripts so that they will be rerun through
# configure if the .in file is changed.
#
all: $(LIB_STUFF)
include $(TESTBED_SRCDIR)/GNUmakerules
install: all script-install
script-install: $(addprefix $(INSTALL_LIBDIR)/snmpit_test/, $(LIB_STUFF))
control-install:
fs-install:
tipserv-install:
clrhouse-install:
clean:
$(INSTALL_DIR)/lib/snmpit_test/%: %
@echo "Installing $<"
-mkdir -p $(INSTALL_DIR)/lib/snmpit_test
$(INSTALL) $< $@
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2009 University of Utah and the Flux Group.
# All rights reserved.
#
#
# snmpit module for APC MasterSwitch power controllers
#
# supports new(ip), power(on|off|cyc[le],port), status
#
package snmpit_apc;
$| = 1; # Turn off line buffering on output
use SNMP;
use strict;
sub new($$;$) {
# The next two lines are some voodoo taken from perltoot(1)
my $proto = shift;
my $class = ref($proto) || $proto;
my $devicename = shift;
my $debug = shift;
if (!defined($debug)) {
$debug = 0;
}
if ($debug) {
print "snmpit_apm module initializing... debug level $debug\n";
}
$SNMP::debugging = ($debug - 5) if $debug > 5;
my $mibpath = "/usr/local/share/snmp/mibs";
&SNMP::addMibDirs($mibpath);
&SNMP::addMibFiles("$mibpath/SNMPv2-SMI.txt",
"$mibpath/SNMPv2-MIB.txt",
"$mibpath/RFC1155-SMI.txt",
"$mibpath/PowerNet-MIB.txt");
$SNMP::save_descriptions = 1; # must be set prior to mib initialization
SNMP::initMib(); # parses default list of Mib modules
$SNMP::use_enums = 1; #use enum values instead of only ints
print "Opening SNMP session to $devicename..." if $debug;
my $sess =new SNMP::Session(DestHost => $devicename, Community => 'private', Version => '1');
if (!defined($sess)) {
warn("ERROR: Unable to connect to $devicename via SNMP\n");
return undef;
}
my $self = {};
$self->{SESS} = $sess;
$self->{DEBUG} = $debug;
$self->{DEVICENAME} = $devicename;
bless($self,$class);
return $self;
}
my %CtlOIDS = (
default => ["sPDUOutletCtl",
"outletOn", "outletOff", "outletReboot"],
rPDU => ["rPDUOutletControlOutletCommand",
"immediateOn", "immediateOff", "immediateReboot"]
);
sub power {
my $self = shift;
my $op = shift;
my @ports = @_;
my $oids = $CtlOIDS{"default"};
my $type = SNMP::translateObj($self->{SESS}->get("sysObjectID.0"));
if (defined($type) &&
$type eq "masterSwitchrPDU") { $oids = $CtlOIDS{"rPDU"}; }
# "sPDUOutletCtl" is ".1.3.6.1.4.1.318.1.1.4.4.2.1.3";
if ($op eq "on") { $op = @$oids[1]; }
elsif ($op eq "off") { $op = @$oids[2]; }
elsif ($op =~ /cyc/) { $op = @$oids[3]; }
my $errors = 0;
foreach my $port (@ports) {
print STDERR "**** Controlling port $port\n" if ($self->{DEBUG} > 1);
if ($self->UpdateField(@$oids[0],$port,$op)) {
print STDERR "Outlet #$port control failed.\n";
$errors++;
}
}
return $errors;
}
sub status {
my $self = shift;
my $statusp = shift;
my %status;
my $StatOID = ".1.3.6.1.4.1.318.1.1.4.2.2";
my $Status = 0;
$Status = $self->{SESS}->get([[$StatOID,0]]);
if (!defined $Status) {
print STDERR $self->{DEVICENAME}, ": no answer from device\n";
return 1;
}
print("Status is '$Status'\n") if $self->{DEBUG};
if ($statusp) {
my @stats = split '\s+', $Status;
my $o = 1;
foreach my $ostat (@stats) {
my $outlet = "outlet$o";
$status{$outlet} = $ostat;
$o++;
}
%$statusp = %status;
}
#
# We can retrieve the total amperage in use (in tenths of amps)
# on an APC by retrieving the rPDULoadStatusLoad. There are
# entries for each of the phases of power that the device supports,
# and for each of the banks of power it provides.
#
# We could add either the phases or the banks, but since the phases
# come first, we use them. We grab the number of phases supported,
# then use that as a limit on how many status load values we retrieve.
#
# The OID to retrieve the phases is: ".1.3.6.1.4.1.318.1.1.12.1.9"
# for more recent units, or: ".1.3.6.1.4.1.318.1.1.12.2.1.2"
# for older ones;
# the load status table OID is: ".1.3.6.1.4.1.318.1.1.12.2.3.1.1.2".
#
my $phases;
$phases = $self->{SESS}->get([["rPDUIdentDeviceNumPhases",0]]);
if (!$phases) {
# not all models support this MIB, try another
$phases = $self->{SESS}->get([["rPDULoadDevNumPhases",0]]);
if (!$phases) {
# some don't support either, bail.
print STDERR "Query phase: IdentDeviceNumPhases/LoadDevNumPhases failed\n"
if $self->{DEBUG};
return 0;
}
}
print "Okay.\nPhase report was '$phases'\n" if $self->{DEBUG};
my ($varname, $index, $power, $val, $done);
my $oid = ["rPDULoadStatusLoad",1];
$self->{SESS}->get($oid);
while ($$oid[0] =~ /rPDULoad/) {
($varname, $index, $val) = @{$oid};
if ($varname eq "rPDULoadStatusLoad") {
if ($index <= $phases) {
print "Raw current value $val\n" if $self->{DEBUG};
$status{current} += $val;
}
}
$self->{SESS}->getnext($oid);
}
print "Total raw current is $status{current}\n" if $self->{DEBUG};
$status{current} /= 10;
if ($statusp) {
%$statusp = %status;
}
return 0;
}
sub UpdateField {
my ($self,$OID,$port,$val) = @_;
print "sess=$self->{SESS} $OID $port $val\n" if $self->{DEBUG} > 1;
my $Status = 0;
my $retval;
print "Checking port $port of $self->{DEVICENAME} for $val..." if $self->{DEBUG};
$Status = $self->{SESS}->get([[$OID,$port]]);
if (!defined $Status) {
print STDERR "Port $port, change to $val: No answer from device\n";
return 1;
} else {
print "Okay.\nPort $port was $Status\n" if $self->{DEBUG};
if ($Status ne $val) {
print "Setting $port to $val..." if $self->{DEBUG};
$retval = $self->{SESS}->set([[$OID,$port,$val,"INTEGER"]]);
print "Set returned '$retval'" if $self->{DEBUG};
if ($retval) { return 0; } else { return 1; }
}
return 0;
}
}
# End with true
1;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/perl -w
#
# EMULAB-LGPL
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
# All rights reserved.
#
#
# snmpit module for Intel EtherExpress 510T switches. This module is largely
# just a wrapper around snmpit_intel, but is here just in case we ever need to
# contact multiple switches (which may happen if we move to port-based (instead
# of MAC-based) VLANs.) For now, though, pretty much everything just calls
# $self->{LEADER}->foo()
#
package snmpit_intel_stack;
use strict;
$| = 1; # Turn off line buffering on output
use English;
use SNMP;
use snmpit_lib;
use libdb;
#
# Creates a new object. A list of devices that will be operated on is given
# 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 an Intel 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_intel_stack class
#
sub new($$$@) {
# The next two lines are some voodoo taken from perltoot(1)
my $proto = shift;
my $class = ref($proto) || $proto;
my $stack_id = shift;
my $debuglevel = shift;
my @devicenames = @_; # Devicenames are not presently needed for Intel
# stacks
#
# Create the actual object
#
my $self = {};
#
# Set up some defaults
#
if (defined $debuglevel) {
$self->{DEBUG} = $debuglevel;
} else {
$self->{DEBUG} = 0;
}
#
# The stackid just happens to also be leader of the stack
#
$self->{STACKID} = $stack_id;
#
# We only need to create 1 snmpit_intel object, since we only have to
# talk to one (for now) to do all the setup we need. 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;
use snmpit_intel;
$self->{LEADER} = new snmpit_intel($leader_name,$self->{DEBUG});
#
# Check for failed object creation
#
if (!$self->{LEADER}) {
#
# The snmpit_intel object has already printed an error message,
# so we'll just return an error
#
return undef;
}
bless($self,$class);
return $self;
}
#
# NOTE: See snmpit_cisco_stack for descriptions of these functions.
# XXX: Document these functions
#
sub listVlans($) {
my $self = shift;
return $self->{LEADER}->listVlans();
}
sub listPorts($) {
my $self = shift;
return $self->{LEADER}->listPorts();
}
sub setPortVlan($$@) {
my $self = shift;
my $vlan_id = shift;
my @ports = @_;
return $self->{LEADER}->setPortVlan($vlan_id,@ports);
}
sub createVlan($$$;@) {
my $self = shift;
my $vlan_id = shift;