All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

Commit d5efea53 authored by Leigh B Stoller's avatar Leigh B Stoller

Commit old changes; lots of stuff moved to initilo script, which

operates on a single node given ilo password and node_id.
parent e7ca6166
......@@ -43,7 +43,6 @@ my $impotent = 0;
my $ipmode = 0;
my %ilomap = ();
my %ctrlmap = ();
my $tempfile = "/tmp/$$.xml";
#
# Configure variables
......@@ -51,9 +50,7 @@ my $tempfile = "/tmp/$$.xml";
my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $LEASES = "/var/db/dhcpd.leases";
my $ILOPSWD = "$TB/etc/ilo.pswd";
my $SRCDIR = "@srcdir@";
my $CURL = "/usr/local/bin/curl";
my $ADDMNG = "$TB/sbin/management_iface";
my $DSAKEY = "/root/.ssh/id_dsa";
my $SUDO = "/usr/local/bin/sudo";
......@@ -61,9 +58,6 @@ my $WAP = "$TB/sbin/withadminprivs";
# Protos
sub Fatal($);
sub ChangeBootOrder($);
sub SendXML($$);
sub SetupControlNode($$);
# un-taint path
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/site/bin';
......@@ -98,11 +92,6 @@ if (defined($options{"d"})) {
if (defined($options{"n"})) {
$impotent = 1;
}
if (defined($options{"i"})) {
$ipmode = 1;
}
Fatal("$ILOPSWD does not exist")
if (! -e $ILOPSWD);
#
# Must be root if actually doing this.
......@@ -111,32 +100,6 @@ if ($UID && !$impotent) {
Fatal("This script must be run as root! Maybe use sudo?")
}
# This is the iLo password for the elabman user we create.
my $elabmanpswd = `cat $ILOPSWD`;
chomp($elabmanpswd);
# The XML goo.
my $setupgoo = `cat $SRCDIR/setupilo.xml`;
my $resetgoo = `cat $SRCDIR/resetilo.xml`;
my $chpswdgoo = `cat $SRCDIR/chpswd.xml`;
# The pubkey.
my $pubkey = `cat ${DSAKEY}.pub`;
if ($?) {
Fatal("Cannot read ${DSAKEY}.pub");
}
chomp($pubkey);
# Need to kill off the comment.
if ($pubkey =~ /^(ssh-dss\s+[^\ ]*)/) {
$pubkey = $1;
}
if ($ipmode) {
usage()
if (@ARGV != 2);
exit(SetupControlNode($ARGV[0], $ARGV[1]));
}
usage()
if (@ARGV != 1);
......@@ -248,25 +211,8 @@ foreach my $map (values(%macmap)) {
}
#
# Before we create the interface, make sure we can install our
# login/password/key info on the ilo.
#
# Replace the appropriate parts of the XML goo.
#
my $xmlgoo = sprintf($setupgoo, $ilopswd, $elabmanpswd, $pubkey);
if (SendXML($tempIP, $xmlgoo)) {
Fatal("Failed to send xmlgoo to $tempIP");
}
#
# The boot order cannot be changed via ribcl. What a pain.
#
if (ChangeBootOrder($tempIP)) {
Fatal("Failed to change the boot order on $ilomac ($iloIP)")
}
#
# Add the management interface
# Add the management interface. The interfaces table will now have
# a proper DHCP entry for it.
#
my $mcmd =
"$ADDMNG -t ilo3 -a key -s - $node_id $ilomac $iloIP elabman $DSAKEY";
......@@ -280,186 +226,12 @@ foreach my $map (values(%macmap)) {
}
#
# This changes the Administrator password. We do this cause it is
# an 8 digit number, and the login is well known. So eventually it
# can be guessed.
#
# We set it the same as the elabman password for now, but that
# might change.
#
$xmlgoo = sprintf($chpswdgoo, $ilopswd, $elabmanpswd);
if (SendXML($ip, $xmlgoo)) {
Fatal("Failed to send chpswd xml to $ip");
}
#
# This resets the ilo so that it will DHCP again and get its new IP.
# Note different password.
#
$xmlgoo = sprintf($resetgoo, $elabmanpswd);
if (SendXML($tempIP, $xmlgoo)) {
Fatal("Failed to send xmlgoo to $tempIP");
}
}
#
# SSH over to change the boot order,
# The "expect" like stuff copied from power_ilo ...
#
sub ChangeBootOrder($)
{
my ($ip) = @_;
my @args = ("ssh", "-tt", "-i", ${DSAKEY}, "elabman\@${ip}");
print "@args\n";
return 0
if ($impotent);
if (! socketpair(CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC)) {
Fatal("socketpair failed: $!");
}
CHILD->autoflush(1);
PARENT->autoflush(1);
my $childpid = fork();
if (! $childpid) {
close(CHILD);
#
# Dup our descriptors to the parent, and exec the program.
# The parent then talks to it read/write.
#
open(STDIN, "<&PARENT") || die "Can't redirect stdin";
open(STDOUT, ">&PARENT") || die "Can't redirect stdout";
open(STDERR, ">&PARENT") || die "Can't redirect stderr";
exec(@args);
die("ssh exec failed\n");
}
close(PARENT);
my @expect_seq = (['hpiLO-> ',"cd system1/bootconfig1"],
['hpiLO-> ','show bootsource5'],
['hpiLO-> ','set bootsource5 bootorder=1'],
['hpiLO-> ','exit']);
#
# Talk to ssh over the pty: wait for expected output and send responses
#
my @lines = ();
foreach $es (@expect_seq) {
my ($rval,$sval) = @$es;
my $found = 0;
my $line = '';
while (1) {
my $char;
if (read(CHILD,$char,1) != 1) {
warn "Error in read in iLO pseudo expect loop!\n";
print "Had read the following lines:\n";
foreach my $ln (@lines) {
print " $ln\n";
}
last;
}
if ($char eq "\r" || $char eq "\n") {
push @lines,$line;
if ($debug) {
if ($debug > 2) {
print "read '$line' while looking for '$rval'\n";
}
elsif ($line ne '') {
print "$line\n";
}
}
$line = '';
}
else {
$line .= $char;
}
if ($line =~ /$rval$/) {
print CHILD "$sval\r";
print "sent '$sval'\n";
$found = 1;
last;
}
}
if (!$found) {
# some sort of error; try to kill off ssh
kill(15,$childpid);
return -16;
}
}
close(CHILD);
# make sure the local ssh dies:
my $i = 5;
my $dead = 0;
while (--$i) {
my $ret = waitpid($childpid,WNOHANG);
if ($ret == -1 || $ret == $childpid) {
$dead = 1;
last;
}
sleep(1);
}
kill(KILL,$childpid) if (!$dead);
return 0;
}
#
# Send some XML to the ribcl
#
sub SendXML($$)
{
my ($ip, $xmlgoo) = @_;
print $xmlgoo
if ($debug);
# Stick it into a file for curl.
open(XML, ">$tempfile")
or Fatal("Could not create $tempfile");
print XML $xmlgoo;
close(XML);
#
# Ship this off with curl.
# Initialize iLo interface; when done, it is resetting and will get
# new IP.
#
my $cmd = "$CURL -k --data-binary \@${tempfile} https://$ip/ribcl";
print "$cmd\n";
if (!$impotent) {
my $output = emutil::ExecQuiet($cmd);
if ($?) {
print $output;
Fatal("ribcl failed");
}
my @lines = split('\n', $output);
while (@lines) {
my $line = shift(@lines);
print $line
if ($debug);
if ($line =~ /^\s*STATUS="(\w*)"/) {
my $status = hex($1);
if ($status != 0) {
my $line = shift(@lines);
$line =~ s/\s*MESSAGE=//;
print "$line\n";
Fatal("ribcl failed");
}
}
}
}
unlink($tempfile)
if (!$debug);
return 0;
system("$SUDO -u elabman $WAP perl initilo.pl $tempIP $ilopswd");
fatal("Could not initialize ilo")
if ($?);
}
exit(0);
......@@ -471,22 +243,3 @@ sub Fatal($)
die("*** $0:\n".
" $msg\n");
}
#
# Setup the control node.
#
sub SetupControlNode($$)
{
my ($ip, $ilopswd) = @_;
my $xmlgoo = sprintf($setupgoo, $ilopswd, $elabmanpswd, $pubkey);
if (SendXML($ip, $xmlgoo)) {
Fatal("Failed to send setup xml to $ip");
}
$xmlgoo = sprintf($chpswdgoo, $ilopswd, $elabmanpswd);
if (SendXML($ip, $xmlgoo)) {
Fatal("Failed to send chpswd xml to $ip");
}
return 0;
}
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