2007-11-19 21:15:45 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
package xCAT_plugin::yaboot;
|
|
|
|
use Data::Dumper;
|
|
|
|
use Sys::Syslog;
|
2008-02-03 00:01:35 +00:00
|
|
|
use xCAT::Scope;
|
2008-03-04 16:28:06 +00:00
|
|
|
use File::Path;
|
2007-11-19 21:15:45 +00:00
|
|
|
use Socket;
|
|
|
|
|
|
|
|
my $request;
|
2008-07-11 20:57:46 +00:00
|
|
|
my %breaknetbootnodes;
|
|
|
|
my %normalnodes;
|
2007-11-19 21:15:45 +00:00
|
|
|
my $callback;
|
2007-11-29 16:01:49 +00:00
|
|
|
my $sub_req;
|
2007-11-19 21:15:45 +00:00
|
|
|
my $dhcpconf = "/etc/dhcpd.conf";
|
|
|
|
my $tftpdir = "/tftpboot";
|
|
|
|
#my $dhcpver = 3;
|
|
|
|
|
|
|
|
my %usage = (
|
2008-05-06 18:24:33 +00:00
|
|
|
"nodeset" => "Usage: nodeset <noderange> [install|shell|boot|runcmd=bmcsetup|netboot|iscsiboot]",
|
2007-11-19 21:15:45 +00:00
|
|
|
);
|
|
|
|
sub handled_commands {
|
|
|
|
return {
|
|
|
|
nodeset => "noderes:netboot"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub check_dhcp {
|
2008-05-15 21:16:33 +00:00
|
|
|
return 1;
|
2007-11-19 21:15:45 +00:00
|
|
|
#TODO: omapi magic to do things right
|
|
|
|
my $node = shift;
|
|
|
|
my $dhcpfile;
|
|
|
|
open ($dhcpfile,$dhcpconf);
|
|
|
|
while (<$dhcpfile>) {
|
|
|
|
if (/host $node\b/) {
|
|
|
|
close $dhcpfile;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $dhcpfile;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub getstate {
|
|
|
|
my $node = shift;
|
|
|
|
if (check_dhcp($node)) {
|
|
|
|
if (-r $tftpdir . "/etc/".$node) {
|
|
|
|
my $fhand;
|
|
|
|
open ($fhand,$tftpdir . "/etc/".$node);
|
|
|
|
my $headline = <$fhand>;
|
|
|
|
close $fhand;
|
|
|
|
$headline =~ s/^#//;
|
|
|
|
chomp($headline);
|
|
|
|
return $headline;
|
|
|
|
} else {
|
|
|
|
return "boot";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return "discover";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setstate {
|
|
|
|
=pod
|
|
|
|
|
|
|
|
This function will manipulate the yaboot structure to match what the noderes/chain tables indicate the node should be booting.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
my $node = shift;
|
2008-07-11 20:57:46 +00:00
|
|
|
my %bphash = %{shift()};
|
|
|
|
my %chainhash = %{shift()};
|
|
|
|
my %machash = %{shift()};
|
|
|
|
my $kern = $bphash{$node}->[0]; #$bptab->getNodeAttribs($node,['kernel','initrd','kcmdline']);
|
2007-11-19 21:15:45 +00:00
|
|
|
my $pcfg;
|
2008-03-04 16:28:06 +00:00
|
|
|
unless (-d "$tftpdir/etc") {
|
|
|
|
mkpath("$tftpdir/etc");
|
|
|
|
}
|
2007-11-19 21:15:45 +00:00
|
|
|
open($pcfg,'>',$tftpdir."/etc/".$node);
|
2008-07-11 20:57:46 +00:00
|
|
|
my $cref=$chainhash{$node}->[0]; #$chaintab->getNodeAttribs($node,['currstate']);
|
2007-11-19 21:15:45 +00:00
|
|
|
if ($cref->{currstate}) {
|
|
|
|
print $pcfg "#".$cref->{currstate}."\n";
|
|
|
|
}
|
|
|
|
print $pcfg "timeout=5\n";
|
2008-07-11 20:57:46 +00:00
|
|
|
$normalnodes{$node}=1; #Assume a normal netboot (well, normal dhcp,
|
|
|
|
#which is normally with a valid 'filename' field,
|
|
|
|
#but the typical ppc case will be 'special' makedhcp
|
|
|
|
#to clear the filename field, so the logic is a little
|
|
|
|
#opposite
|
|
|
|
# $sub_req->({command=>['makedhcp'], #This is currently batched elswhere
|
|
|
|
# node=>[$node]},$callback); #It hopefully will perform correctly
|
|
|
|
if ($cref and $cref->{currstate} eq "boot") {
|
|
|
|
$breaknetbootnodes{$node}=1;
|
|
|
|
delete $normalnodes{$node}; #Signify to omit this from one makedhcp command
|
|
|
|
#$sub_req->({command=>['makedhcp'], #batched elsewhere, this code is stale, hopefully
|
|
|
|
# node=>[$node],
|
|
|
|
# arg=>['-s','filename = \"xcat/nonexistant_file_to_intentionally_break_netboot_for_localboot_to_work\";']},$callback);
|
2007-11-19 21:15:45 +00:00
|
|
|
print $pcfg "bye\n";
|
|
|
|
close($pcfg);
|
|
|
|
} elsif ($kern and $kern->{kernel}) {
|
|
|
|
#It's time to set yaboot for this node to boot the kernel..
|
|
|
|
print $pcfg "image=".$kern->{kernel}."\n\tlabel=xcat\n";
|
|
|
|
if ($kern and $kern->{initrd}) {
|
|
|
|
print $pcfg "\tinitrd=".$kern->{initrd}."\n";
|
|
|
|
}
|
|
|
|
if ($kern and $kern->{kcmdline}) {
|
|
|
|
print $pcfg "\tappend=\"".$kern->{kcmdline}."\"\n";
|
|
|
|
}
|
|
|
|
close($pcfg);
|
|
|
|
my $inetn = inet_aton($node);
|
|
|
|
unless ($inetn) {
|
|
|
|
syslog("local1|err","xCAT unable to resolve IP for $node in yaboot plugin");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else { #TODO: actually, should possibly default to xCAT image?
|
|
|
|
print $pcfg "bye\n";
|
|
|
|
close($pcfg);
|
|
|
|
}
|
|
|
|
my $ip = inet_ntoa(inet_aton($node));;
|
|
|
|
unless ($ip) {
|
|
|
|
syslog("local1|err","xCAT unable to resolve IP in yaboot plugin");
|
|
|
|
return;
|
|
|
|
}
|
2008-02-28 00:17:24 +00:00
|
|
|
my $mactab = xCAT::Table->new('mac');
|
|
|
|
my %ipaddrs;
|
|
|
|
$ipaddrs{$ip} = 1;
|
|
|
|
if ($mactab) {
|
2008-07-11 20:57:46 +00:00
|
|
|
my $ment = $machash{$node}->[0]; #$mactab->getNodeAttribs($node,['mac']);
|
2008-02-28 00:17:24 +00:00
|
|
|
if ($ment and $ment->{mac}) {
|
|
|
|
my @macs = split(/\|/,$ment->{mac});
|
|
|
|
foreach (@macs) {
|
|
|
|
if (/!(.*)/) {
|
2008-03-21 20:00:07 +00:00
|
|
|
if (inet_aton($1)) {
|
|
|
|
$ipaddrs{inet_ntoa(inet_aton($1))} = 1;
|
|
|
|
}
|
2008-02-28 00:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 22:28:30 +00:00
|
|
|
my $hassymlink = eval { symlink("",""); 1 };
|
2008-02-28 00:17:24 +00:00
|
|
|
foreach $ip (keys %ipaddrs) {
|
|
|
|
my @ipa=split(/\./,$ip);
|
|
|
|
my $pname = sprintf("%02x%02x%02x%02x",@ipa);
|
|
|
|
unlink($tftpdir."/etc/".$pname);
|
2008-09-09 22:28:30 +00:00
|
|
|
if ($hassymlink) {
|
|
|
|
symlink($node,$tftpdir."/etc/".$pname);
|
|
|
|
} else {
|
|
|
|
link($tftpdir."/etc/".$node,$tftpdir."/etc/".$pname);
|
|
|
|
}
|
2008-02-28 00:17:24 +00:00
|
|
|
}
|
2007-11-19 21:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $errored = 0;
|
|
|
|
sub pass_along {
|
|
|
|
my $resp = shift;
|
|
|
|
$callback->($resp);
|
2008-05-07 20:45:48 +00:00
|
|
|
if ($resp and ($resp->{errorcode} and $resp->{errorcode}->[0]) or ($resp->{error} and $resp->{error}->[0])) {
|
2007-11-19 21:15:45 +00:00
|
|
|
$errored=1;
|
|
|
|
}
|
2008-05-07 20:45:48 +00:00
|
|
|
foreach (@{$resp->{node}}) {
|
|
|
|
if ($_->{error} or $_->{errorcode}) {
|
|
|
|
$errored=1;
|
|
|
|
}
|
|
|
|
}
|
2007-11-19 21:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-27 20:45:31 +00:00
|
|
|
|
2008-05-02 01:37:02 +00:00
|
|
|
sub preprocess_request {
|
|
|
|
#Assume shared tftp directory for boring people, but for cool people, help sync up tftpdirectory contents when
|
|
|
|
#they specify no sharedtftp in site table
|
|
|
|
my $stab = xCAT::Table->new('site');
|
|
|
|
my $req = shift;
|
2008-06-25 14:50:11 +00:00
|
|
|
|
2008-05-02 01:37:02 +00:00
|
|
|
my $sent = $stab->getAttribs({key=>'sharedtftp'},'value');
|
|
|
|
if ($sent and ($sent->{value} == 0 or $ent->{value} =~ /no/i)) {
|
|
|
|
$req->{'_disparatetftp'}=[1];
|
|
|
|
return xCAT::Scope->get_broadcast_scope($req,@_);
|
|
|
|
}
|
|
|
|
return [$req];
|
|
|
|
}
|
2008-02-03 00:01:35 +00:00
|
|
|
#sub preprocess_request {
|
|
|
|
# my $req = shift;
|
|
|
|
# my $callback = shift;
|
|
|
|
# my %localnodehash;
|
|
|
|
# my %dispatchhash;
|
|
|
|
# my $nrtab = xCAT::Table->new('noderes');
|
|
|
|
# foreach my $node (@{$req->{node}}) {
|
|
|
|
# my $nodeserver;
|
|
|
|
# my $tent = $nrtab->getNodeAttribs($node,['tftpserver']);
|
|
|
|
# if ($tent) { $nodeserver = $tent->{tftpserver} }
|
|
|
|
# unless ($tent and $tent->{tftpserver}) {
|
|
|
|
# $tent = $nrtab->getNodeAttribs($node,['servicenode']);
|
|
|
|
# if ($tent) { $nodeserver = $tent->{servicenode} }
|
|
|
|
# }
|
|
|
|
# if ($nodeserver) {
|
|
|
|
# $dispatchhash{$nodeserver}->{$node} = 1;
|
|
|
|
# } else {
|
|
|
|
# $localnodehash{$node} = 1;
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# my @requests;
|
|
|
|
# my $reqc = {%$req};
|
|
|
|
# $reqc->{node} = [ keys %localnodehash ];
|
|
|
|
# if (scalar(@{$reqc->{node}})) { push @requests,$reqc }
|
|
|
|
#
|
|
|
|
# foreach my $dtarg (keys %dispatchhash) { #iterate dispatch targets
|
|
|
|
# my $reqcopy = {%$req}; #deep copy
|
|
|
|
# $reqcopy->{'_xcatdest'} = $dtarg;
|
|
|
|
# $reqcopy->{node} = [ keys %{$dispatchhash{$dtarg}}];
|
|
|
|
# push @requests,$reqcopy;
|
|
|
|
# }
|
|
|
|
# return \@requests;
|
|
|
|
#}
|
|
|
|
#
|
2007-11-19 21:15:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub process_request {
|
|
|
|
$request = shift;
|
|
|
|
$callback = shift;
|
2007-11-29 16:01:49 +00:00
|
|
|
$sub_req = shift;
|
2008-07-11 20:57:46 +00:00
|
|
|
%breaknetbootnodes=();
|
|
|
|
%normalnnodes=();
|
2008-06-25 14:50:11 +00:00
|
|
|
|
2007-11-19 21:15:45 +00:00
|
|
|
my @args;
|
|
|
|
my @nodes;
|
2008-02-03 00:01:35 +00:00
|
|
|
my @rnodes;
|
2007-11-19 21:15:45 +00:00
|
|
|
if (ref($request->{node})) {
|
2008-02-03 00:01:35 +00:00
|
|
|
@rnodes = @{$request->{node}};
|
2007-11-19 21:15:45 +00:00
|
|
|
} else {
|
2008-02-03 00:01:35 +00:00
|
|
|
if ($request->{node}) { @rnodes = ($request->{node}); }
|
2007-11-19 21:15:45 +00:00
|
|
|
}
|
2008-02-03 00:01:35 +00:00
|
|
|
unless (@rnodes) {
|
2007-11-19 21:15:45 +00:00
|
|
|
if ($usage{$request->{command}->[0]}) {
|
|
|
|
$callback->({data=>$usage{$request->{command}->[0]}});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2008-06-25 14:50:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
#back to normal business
|
2008-05-02 01:37:02 +00:00
|
|
|
#if not shared tftpdir, then filter, otherwise, set up everything
|
|
|
|
if ($req->{_disparatetftp}) { #reading hint from preprocess_command
|
|
|
|
@nodes = ();
|
|
|
|
foreach (@rnodes) {
|
|
|
|
if (xCAT::Utils->nodeonmynet($_)) {
|
|
|
|
push @nodes,$_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
@nodes = @rnodes;
|
|
|
|
}
|
2008-02-03 00:01:35 +00:00
|
|
|
|
2007-11-19 21:15:45 +00:00
|
|
|
if (ref($request->{arg})) {
|
|
|
|
@args=@{$request->{arg}};
|
|
|
|
} else {
|
|
|
|
@args=($request->{arg});
|
|
|
|
}
|
|
|
|
unless ($args[0] eq 'stat' or $args[0] eq 'enact') {
|
|
|
|
$sub_req->({command=>['setdestiny'],
|
|
|
|
node=>\@nodes,
|
|
|
|
arg=>[$args[0]]},\&pass_along);
|
|
|
|
}
|
|
|
|
if ($errored) { return; }
|
2008-07-11 20:57:46 +00:00
|
|
|
my $bptab=xCAT::Table->new('bootparams',-create=>1);
|
|
|
|
my $bphash = $bptab->getNodesAttribs(\@nodes,['kernel','initrd','kcmdline']);
|
2008-07-23 17:50:21 +00:00
|
|
|
my $chaintab=xCAT::Table->new('chain',-create=>1);
|
2008-07-11 20:57:46 +00:00
|
|
|
my $chainhash=$chaintab->getNodesAttribs(\@nodes,['currstate']);
|
|
|
|
my $mactab=xCAT::Table->new('mac',-create=>1);
|
|
|
|
my $machhash=$mactab->getNodesAttribs(\@nodes,['mac']);
|
|
|
|
|
2007-11-19 21:15:45 +00:00
|
|
|
foreach (@nodes) {
|
|
|
|
my %response;
|
|
|
|
$response{node}->[0]->{name}->[0]=$_;
|
|
|
|
if ($args[0] eq 'stat') {
|
|
|
|
$response{node}->[0]->{data}->[0]= getstate($_);
|
|
|
|
$callback->(\%response);
|
|
|
|
} elsif ($args[0]) { #If anything else, send it on to the destiny plugin, then setstate
|
2008-07-11 20:57:46 +00:00
|
|
|
setstate($_,$bphash,$chainhash,$machash);
|
2007-11-19 21:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-14 14:44:18 +00:00
|
|
|
my @normalnodes = keys %normal;
|
2008-07-11 20:57:46 +00:00
|
|
|
$sub_req->({command=>['makedhcp'],
|
|
|
|
node=>\@normalnodes},$callback);
|
|
|
|
my @breaknetboot=keys %breaknetbootnodes;
|
|
|
|
$sub_req->({command=>['makedhcp'],
|
|
|
|
node=>\@breaknetboot,
|
|
|
|
arg=>['-s','filename = \"xcat/nonexistant_file_to_intentionally_break_netboot_for_localboot_to_work\";']},$callback);
|
2008-06-27 14:35:20 +00:00
|
|
|
|
2007-11-19 21:15:45 +00:00
|
|
|
}
|
|
|
|
|
2008-09-26 23:07:45 +00:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
=head3 getNodesetStates
|
|
|
|
returns the nodeset state for the given nodes. The possible nodeset
|
|
|
|
states are: netboot, install, boot and discover.
|
|
|
|
Arguments:
|
|
|
|
nodes --- a pointer to an array of nodes
|
|
|
|
states -- a pointer to a hash table. This hash will be filled by this
|
|
|
|
function node and key and the nodeset stat as the value.
|
|
|
|
Returns:
|
|
|
|
(return code, error message)
|
|
|
|
=cut
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub getNodesetStates {
|
|
|
|
my $noderef=shift;
|
|
|
|
if ($noderef =~ /xCAT_plugin::yaboot/) {
|
|
|
|
$noderef=shift;
|
|
|
|
}
|
|
|
|
my @nodes=@$noderef;
|
|
|
|
my $hashref=shift;
|
|
|
|
|
|
|
|
if (@nodes>0) {
|
|
|
|
foreach my $node (@nodes) {
|
|
|
|
my $tmp=getstate($node);
|
|
|
|
my @a=split(' ', $tmp);
|
|
|
|
$stat = $a[0];
|
|
|
|
$hashref->{$node}=$stat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0, "");
|
|
|
|
}
|
2007-11-19 21:15:45 +00:00
|
|
|
|
|
|
|
1;
|