Commit 9a8aaa60 authored by Leigh B Stoller's avatar Leigh B Stoller

New script to generate the ilo and wiring XML files that are needed

to rebuild the rack. We can't really go back to the original since things
might have changed, and with some racks, we don't actually have the
original ilo file (Utah, UtahDDC).
parent 8fcd9446
#
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -27,7 +27,7 @@ SUBDIR = install/genirack
include $(OBJDIR)/Makeconf
TARGETS = initnodes.pl initilo.pl mknewconfig
TARGETS = initnodes.pl initilo.pl mknewconfig genwires
LIBFILES = addsshkey.xml resetilo.xml chpswd.xml noipmi.xml setupilo.xml
#
......
#!/usr/bin/perl -w
#
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use English;
use Getopt::Std;
use XML::Simple;
use Data::Dumper;
sub usage()
{
exit(-1);
}
my $optlist = "dwi";
my $debug = 0;
my $genwires = 0;
my $genilo = 0;
#
# Configure variables
#
my $TB = "@prefix@";
my $ILOPSWD = "$TB/etc/ilo.pswd";
# Protos
sub Fatal($);
sub GenXML(@);
sub GenWires(@);
# un-taint path
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use emdb;
use Node;
use Interface;
#
# Turn off line buffering on output
#
$| = 1;
#
# Parse command arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"w"})) {
$genwires = 1;
}
if (defined($options{"x"})) {
$genilo = 1;
}
Fatal("$ILOPSWD does not exist")
if (! -e $ILOPSWD);
# This is the iLo password for the elabman user we create.
my $ilopswd = `cat $ILOPSWD`;
chomp($ilopswd);
my @tmp = Node->LookupByType("dl360");
if (!@tmp) {
Fatal("No nodes!");
}
# Reorder by priority slot.
my @nodes = sort {$a->priority() <=> $b->priority()} @tmp;
if ($genwires) {
GenWires(@nodes);
}
elsif ($genilo) {
GenXML(@nodes);
}
exit(0);
sub GenXML(@)
{
my @nodes = @_;
print "<DELABS-R01>\n";
foreach my $node (@nodes) {
my ($ilomac);
my %nicmacs = ();
my @interfaces;
if (Interface->LookupAll($node, \@interfaces)) {
Fatal("Could not get interfaces for $node");
}
foreach my $interface (@interfaces) {
if ($interface->role() eq "ctrl") {
$nicmacs{"nic1mac"} = $interface->mac();
}
elsif ($interface->role() eq "expt") {
if ($interface->iface() =~ /^eth(\d+)$/) {
my $vname = "nic" . ($1 + 1) . "mac";
$nicmacs{$vname} = $interface->mac();
}
}
elsif ($interface->role() eq "mngmnt") {
$ilomac = $interface->mac();
}
}
my $location = sprintf("U%02d", $node->priority());
print "<Device>\n";
print " <u_location>$location</u_location>\n";
print " <lo_mac>$ilomac</lo_mac>\n";
print " <lo_password>$ilopswd</lo_password>\n";
print " <nic1mac>" . $nicmacs{"nic1mac"} . "</nic1mac>\n";
print " <nic2mac>" . $nicmacs{"nic2mac"} . "</nic2mac>\n";
print " <nic3mac>" . $nicmacs{"nic3mac"} . "</nic3mac>\n";
print " <nic4mac>" . $nicmacs{"nic4mac"} . "</nic4mac>\n";
print "</Device>\n";
}
print "<Device>\n";
print " <u_location>U34</u_location>\n";
print " <lo_password>$ilopswd</lo_password>\n";
print "</Device>\n";
print "</DELABS-R01>\n";
}
sub GenWires(@)
{
my @nodes = @_;
print "<wiring>\n";
foreach my $node (@nodes) {
my @interfaces;
my $location = sprintf("U%02d", $node->priority());
if (Interface->LookupAll($node, \@interfaces)) {
Fatal("Could not get interfaces for $node");
}
foreach my $interface (@interfaces) {
PrintInterface($interface, $location);
}
}
print "<wiring>\n";
}
sub PrintInterface($$)
{
my ($interface, $location) = @_;
my $node_id = $interface->node_id();
my $iface = $interface->iface();
my $role = $interface->role();
my $card1 = $interface->card();
my $port1 = $interface->port();
my $card2 = $interface->switch_card();
my $port2 = $interface->switch_port();
my $switch_id = $interface->switch_id();
print "<wire>\n";
print " <UXX>$location</UXX>\n";
print " <node_id1>$node_id</node_id1>\n";
print " <iface>$iface</iface>\n";
print " <role>$role</role>\n";
print " <card1>$card1</card1>\n";
print " <port1>$port1</port1>\n";
print " <node_id2>$switch_id</node_id2>\n";
print " <card2>$card2</card2>\n";
print " <port2>$port2</port2>\n";
print "</wire>\n";
}
sub Fatal($)
{
my ($msg) = @_;
die("*** $0:\n".
" $msg\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