2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
package xCAT_plugin::pxe;
|
|
|
|
use Data::Dumper;
|
|
|
|
use Sys::Syslog;
|
|
|
|
use Socket;
|
2008-03-04 19:36:35 +00:00
|
|
|
use File::Copy;
|
2009-06-29 18:37:45 +00:00
|
|
|
use File::Path;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
my $request;
|
|
|
|
my $callback;
|
|
|
|
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-10-26 22:44:33 +00:00
|
|
|
);
|
|
|
|
sub handled_commands {
|
|
|
|
return {
|
|
|
|
nodeset => "noderes:netboot"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub check_dhcp {
|
2008-05-15 21:16:33 +00:00
|
|
|
return 1;
|
2007-10-26 22:44:33 +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)) {
|
2009-06-29 18:37:45 +00:00
|
|
|
if (-r $tftpdir . "/xcat/xnba/nodes/".$node) {
|
|
|
|
my $fhand;
|
|
|
|
open ($fhand,$tftpdir . "/xcat/xnba/nodes/".$node);
|
|
|
|
my $headline = <$fhand>;
|
|
|
|
$headline = <$fhand>; #second line is the comment now...
|
|
|
|
close $fhand;
|
|
|
|
$headline =~ s/^#//;
|
|
|
|
chomp($headline);
|
|
|
|
return $headline;
|
|
|
|
} elsif (-r $tftpdir . "/pxelinux.cfg/".$node) {
|
2007-10-26 22:44:33 +00:00
|
|
|
my $fhand;
|
|
|
|
open ($fhand,$tftpdir . "/pxelinux.cfg/".$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 pxelinux.cfg structure to match what the noderes/chain tables indicate the node should be booting.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
my $node = shift;
|
2008-07-11 19:02:39 +00:00
|
|
|
my %bphash = %{shift()};
|
|
|
|
my %chainhash = %{shift()};
|
|
|
|
my %machash = %{shift()};
|
|
|
|
my $kern = $bphash{$node}->[0]; #$bptab->getNodeAttribs($node,['kernel','initrd','kcmdline']);
|
2009-06-29 18:37:45 +00:00
|
|
|
if ($kern->{addkcmdline}) { #Implement the kcmdline append here for
|
|
|
|
#most generic, least code duplication
|
|
|
|
$kern->{kcmdline} .= " ".$kern->{addkcmdline};
|
|
|
|
}
|
2009-03-18 14:11:30 +00:00
|
|
|
if ($kern->{kcmdline} =~ /!myipfn!/) {
|
|
|
|
my $ipfn = xCAT::Utils->my_ip_facing($node);
|
2009-03-18 19:37:54 +00:00
|
|
|
unless ($ipfn) {
|
|
|
|
my @myself = xCAT::Utils->determinehostname();
|
|
|
|
my $myname = $myself[(scalar @myself)-1];
|
|
|
|
$callback->(
|
|
|
|
{
|
|
|
|
error => [
|
|
|
|
"$myname: Unable to determine or reasonably guess the image server for $node"
|
|
|
|
],
|
|
|
|
errorcode => [1]
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2009-03-18 14:11:30 +00:00
|
|
|
$kern->{kcmdline} =~ s/!myipfn!/$ipfn/;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
my $pcfg;
|
2009-06-29 18:42:23 +00:00
|
|
|
unlink($tftpdir."/xcat/xnba/nodes/".$node.".pxelinux");
|
2009-06-29 18:37:45 +00:00
|
|
|
open($pcfg,'>',$tftpdir."/xcat/xnba/nodes/".$node);
|
2008-07-11 19:02:39 +00:00
|
|
|
my $cref=$chainhash{$node}->[0]; #$chaintab->getNodeAttribs($node,['currstate']);
|
2009-06-29 18:37:45 +00:00
|
|
|
print $pcfg "#!gpxe\n";
|
2007-10-26 22:44:33 +00:00
|
|
|
if ($cref->{currstate}) {
|
|
|
|
print $pcfg "#".$cref->{currstate}."\n";
|
|
|
|
}
|
2008-07-11 19:02:39 +00:00
|
|
|
if ($cref and $cref->{currstate} eq "boot") {
|
2009-07-20 14:32:23 +00:00
|
|
|
print $pcfg "hdboot\n";
|
2007-10-26 22:44:33 +00:00
|
|
|
close($pcfg);
|
|
|
|
} elsif ($kern and $kern->{kernel}) {
|
2009-06-29 18:37:45 +00:00
|
|
|
if ($kern->{kernel} =~ /!/) { #TODO: deprecate this, do stateless Xen like stateless ESXi
|
|
|
|
my $hypervisor;
|
|
|
|
my $kernel;
|
|
|
|
($kernel,$hypervisor) = split /!/,$kern->{kernel};
|
|
|
|
print $pcfg " set 209:string xcat/xnba/nodes/$node.pxelinux\n";
|
|
|
|
print $pcfg " set 210:string http://".'${next-server}'."/tftpboot/\n";
|
|
|
|
print $pcfg " imgfetch -n pxelinux.0 http://".'${next-server}'."/tftpboot/pxelinux.0\n";
|
|
|
|
print $pcfg " imgload pxelinux.0\n";
|
|
|
|
print $pcfg " imgexec pxelinux.0\n";
|
|
|
|
close($pcfg);
|
|
|
|
open($pcfg,'>',$tftpdir."/xcat/xnba/nodes/".$node.".pxelinux");
|
|
|
|
print $pcfg "DEFAULT xCAT\nLABEL xCAT\n KERNEL mboot.c32\n";
|
|
|
|
print $pcfg " APPEND $hypervisor --- $kernel ".$kern->{kcmdline}." --- ".$kern->{initrd}."\n";
|
2009-02-21 14:25:29 +00:00
|
|
|
} else {
|
2009-06-29 18:37:45 +00:00
|
|
|
if ($kern->{kernel} =~ /\.c32\z/) { #gPXE comboot support seems insufficient, chain pxelinux instead
|
|
|
|
print $pcfg " set 209:string xcat/xnba/nodes/$node.pxelinux\n";
|
|
|
|
print $pcfg " set 210:string http://".'${next-server}'."/tftpboot/\n";
|
|
|
|
print $pcfg " imgfetch -n pxelinux.0 http://".'${next-server}'."/tftpboot/pxelinux.0\n";
|
|
|
|
print $pcfg " imgload pxelinux.0\n";
|
|
|
|
print $pcfg " imgexec pxelinux.0\n";
|
|
|
|
close($pcfg);
|
|
|
|
open($pcfg,'>',$tftpdir."/xcat/xnba/nodes/".$node.".pxelinux");
|
|
|
|
#It's time to set pxelinux for this node to boot the kernel..
|
|
|
|
print $pcfg "DEFAULT xCAT\nLABEL xCAT\n";
|
|
|
|
print $pcfg " KERNEL ".$kern->{kernel}."\n";
|
|
|
|
if ($kern->{initrd} or $kern->{kcmdline}) {
|
|
|
|
print $pcfg " APPEND ";
|
|
|
|
}
|
|
|
|
if ($kern and $kern->{initrd}) {
|
|
|
|
print $pcfg "initrd=".$kern->{initrd}." ";
|
|
|
|
}
|
|
|
|
if ($kern and $kern->{kcmdline}) {
|
|
|
|
print $pcfg $kern->{kcmdline}."\n";
|
|
|
|
} else {
|
|
|
|
print $pcfg "\n";
|
|
|
|
}
|
|
|
|
} else { #other than comboot/multiboot, we won't have need of pxelinux
|
|
|
|
print $pcfg "imgfetch -n kernel http://".'${next-server}/tftpboot/'.$kern->{kernel}."\n";
|
|
|
|
print $pcfg "imgload kernel\n";
|
|
|
|
if ($kern->{kcmdline}) {
|
|
|
|
print $pcfg "imgargs kernel ".$kern->{kcmdline}."\n";
|
|
|
|
}
|
|
|
|
if ($kern->{initrd}) {
|
|
|
|
print $pcfg "imgfetch http://".'${next-server}'."/tftpboot/".$kern->{initrd}."\n";
|
|
|
|
}
|
|
|
|
print $pcfg "imgexec kernel\n";
|
|
|
|
}
|
2009-02-21 14:25:29 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
close($pcfg);
|
|
|
|
my $inetn = inet_aton($node);
|
|
|
|
unless ($inetn) {
|
|
|
|
syslog("local1|err","xCAT unable to resolve IP for $node in pxe plugin");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else { #TODO: actually, should possibly default to xCAT image?
|
|
|
|
print $pcfg "LOCALBOOT 0\n";
|
|
|
|
close($pcfg);
|
|
|
|
}
|
2008-02-28 00:17:24 +00:00
|
|
|
my $mactab = xCAT::Table->new('mac'); #to get all the hostnames
|
|
|
|
my %ipaddrs;
|
2008-07-11 19:02:39 +00:00
|
|
|
unless (inet_aton($node)) {
|
|
|
|
syslog("local1|err","xCAT unable to resolve IP in pxe plugin");
|
|
|
|
return;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
my $ip = inet_ntoa(inet_aton($node));;
|
|
|
|
unless ($ip) {
|
|
|
|
syslog("local1|err","xCAT unable to resolve IP in pxe plugin");
|
|
|
|
return;
|
|
|
|
}
|
2008-02-28 00:17:24 +00:00
|
|
|
$ipaddrs{$ip} = 1;
|
|
|
|
if ($mactab) {
|
2008-07-11 19:02:39 +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."/pxelinux.cfg/".$pname);
|
2008-09-09 22:28:30 +00:00
|
|
|
if ($hassymlink) {
|
|
|
|
symlink($node,$tftpdir."/pxelinux.cfg/".$pname);
|
|
|
|
} else {
|
|
|
|
link($tftpdir."/pxelinux.cfg/".$node,$tftpdir."/pxelinux.cfg/".$pname);
|
|
|
|
}
|
2008-02-28 00:17:24 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +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-10-26 22:44:33 +00:00
|
|
|
$errored=1;
|
|
|
|
}
|
2008-05-07 20:45:48 +00:00
|
|
|
foreach (@{$resp->{node}}) {
|
|
|
|
if ($_->{error} or $_->{errorcode}) {
|
|
|
|
$errored=1;
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-02 01:43:35 +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;
|
|
|
|
my $sent = $stab->getAttribs({key=>'sharedtftp'},'value');
|
2009-03-12 17:39:04 +00:00
|
|
|
if ($sent and ($sent->{value} == 0 or $sent->{value} =~ /no/i)) {
|
2008-05-02 01:43:35 +00:00
|
|
|
$req->{'_disparatetftp'}=[1];
|
2009-03-28 15:03:36 +00:00
|
|
|
if ($req->{inittime}->[0]) {
|
2009-03-28 06:15:05 +00:00
|
|
|
return [$req];
|
|
|
|
}
|
2008-05-02 01:43:35 +00:00
|
|
|
return xCAT::Scope->get_broadcast_scope($req,@_);
|
|
|
|
}
|
|
|
|
return [$req];
|
|
|
|
}
|
2008-04-23 14:01:46 +00:00
|
|
|
#sub preprocess_request {
|
|
|
|
# my $req = shift;
|
|
|
|
# $callback = shift;
|
2009-07-15 15:39:16 +00:00
|
|
|
# if ($req->{_xcatpreprocessed}->[0] == 1) { return [$req]; }
|
2008-04-23 14:01:46 +00:00
|
|
|
# my @requests = ({%$req}); #Start with a straight copy to reflect local instance
|
|
|
|
# my $sitetab = xCAT::Table->new('site');
|
|
|
|
# (my $ent) = $sitetab->getAttribs({key=>'xcatservers'},'value');
|
|
|
|
# $sitetab->close;
|
|
|
|
# if ($ent and $ent->{value}) {
|
|
|
|
# foreach (split /,/,$ent->{value}) {
|
|
|
|
# if (xCAT::Utils->thishostisnot($_)) {
|
|
|
|
# my $reqcopy = {%$req};
|
|
|
|
# $reqcopy->{'_xcatdest'} = $_;
|
2009-07-15 15:39:16 +00:00
|
|
|
# $reqcopy->{_xcatpreprocessed}->[0] = 1;
|
2008-04-23 14:01:46 +00:00
|
|
|
# push @requests,$reqcopy;
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# return \@requests;
|
|
|
|
#}
|
2008-02-02 19:39:33 +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-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
sub process_request {
|
|
|
|
$request = shift;
|
|
|
|
$callback = shift;
|
|
|
|
my $sub_req = shift;
|
|
|
|
my @args;
|
|
|
|
my @nodes;
|
2008-02-02 19:39:33 +00:00
|
|
|
my @rnodes;
|
2007-10-26 22:44:33 +00:00
|
|
|
if (ref($request->{node})) {
|
2008-02-02 19:39:33 +00:00
|
|
|
@rnodes = @{$request->{node}};
|
2007-10-26 22:44:33 +00:00
|
|
|
} else {
|
2008-02-02 19:39:33 +00:00
|
|
|
if ($request->{node}) { @rnodes = ($request->{node}); }
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2009-01-08 07:00:27 +00:00
|
|
|
|
|
|
|
my $args_ref = $request->{arg};
|
|
|
|
if(scalar grep(/^--version$|^-v$/, @$args_ref)) {
|
|
|
|
my $ver = xCAT::Utils->Version();
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0]="$ver";
|
|
|
|
$callback->(\%rsp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-02 19:39:33 +00:00
|
|
|
unless (@rnodes) {
|
2007-10-26 22:44:33 +00:00
|
|
|
if ($usage{$request->{command}->[0]}) {
|
|
|
|
$callback->({data=>$usage{$request->{command}->[0]}});
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2008-06-25 14:50:11 +00:00
|
|
|
|
2008-05-02 01:43:35 +00:00
|
|
|
#if not shared, then help sync up
|
2009-05-07 13:58:31 +00:00
|
|
|
if ($request->{'_disparatetftp'}->[0]) { #reading hint from preprocess_command
|
2008-05-02 01:43:35 +00:00
|
|
|
@nodes = ();
|
|
|
|
foreach (@rnodes) {
|
|
|
|
if (xCAT::Utils->nodeonmynet($_)) {
|
|
|
|
push @nodes,$_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
@nodes = @rnodes;
|
|
|
|
}
|
|
|
|
|
2008-02-26 18:48:43 +00:00
|
|
|
if (! -r "$tftpdir/pxelinux.0") {
|
2008-06-27 15:57:58 +00:00
|
|
|
unless (-r "/usr/lib/syslinux/pxelinux.0" or -r "/usr/share/syslinux/pxelinux.0") {
|
2008-02-26 18:48:43 +00:00
|
|
|
$callback->({error=>["Unable to find pxelinux.0 "],errorcode=>[1]});
|
|
|
|
return;
|
2008-06-27 15:57:58 +00:00
|
|
|
}
|
|
|
|
if (-r "/usr/lib/syslinux/pxelinux.0") {
|
|
|
|
copy("/usr/lib/syslinux/pxelinux.0","$tftpdir/pxelinux.0");
|
|
|
|
} else {
|
|
|
|
copy("/usr/share/syslinux/pxelinux.0","$tftpdir/pxelinux.0");
|
2008-02-26 18:48:43 +00:00
|
|
|
}
|
|
|
|
chmod(0644,"$tftpdir/pxelinux.0");
|
2008-06-27 15:57:58 +00:00
|
|
|
}
|
|
|
|
unless ( -r "$tftpdir/pxelinux.0" ) {
|
|
|
|
$callback->({errror=>["Unable to find pxelinux.0 from syslinux"],errorcode=>[1]});
|
|
|
|
return;
|
|
|
|
}
|
2008-02-02 19:39:33 +00:00
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
if (ref($request->{arg})) {
|
|
|
|
@args=@{$request->{arg}};
|
|
|
|
} else {
|
|
|
|
@args=($request->{arg});
|
|
|
|
}
|
2009-05-07 04:31:33 +00:00
|
|
|
$errored=0;
|
2009-03-28 04:25:03 +00:00
|
|
|
unless ($args[0] eq 'stat') { # or $args[0] eq 'enact') {
|
2007-10-26 22:44:33 +00:00
|
|
|
$sub_req->({command=>['setdestiny'],
|
|
|
|
node=>\@nodes,
|
|
|
|
arg=>[$args[0]]},\&pass_along);
|
|
|
|
}
|
|
|
|
if ($errored) { return; }
|
2008-07-11 19:02:39 +00:00
|
|
|
#Time to actually configure the nodes, first extract database data with the scalable calls
|
|
|
|
my $bptab = xCAT::Table->new('bootparams',-create=>1);
|
|
|
|
my $chaintab = xCAT::Table->new('chain');
|
|
|
|
my $mactab = xCAT::Table->new('mac'); #to get all the hostnames
|
2009-06-29 18:37:45 +00:00
|
|
|
my %bphash = %{$bptab->getNodesAttribs(\@nodes,[qw(kernel initrd kcmdline addkcmdline)])};
|
2008-07-11 19:02:39 +00:00
|
|
|
my %chainhash = %{$chaintab->getNodesAttribs(\@nodes,[qw(currstate)])};
|
|
|
|
my %machash = %{$mactab->getNodesAttribs(\@nodes,[qw(mac)])};
|
2009-06-29 18:37:45 +00:00
|
|
|
mkpath($tftpdir."/xcat/xnba/nodes/");
|
2007-10-26 22:44:33 +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
|
2009-03-18 18:45:46 +00:00
|
|
|
($rc,$errstr) = setstate($_,\%bphash,\%chainhash,\%machash);
|
2009-03-18 14:11:30 +00:00
|
|
|
if ($rc) {
|
|
|
|
$response{node}->[0]->{errorcode}->[0]= $rc;
|
|
|
|
$response{node}->[0]->{errorc}->[0]= $errstr;
|
|
|
|
$callback->(\%response);
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-28 15:03:36 +00:00
|
|
|
if ($request->{inittime}->[0]) { return; } #Don't bother to try dhcp binding changes if sub_req not passed, i.e. service node build time
|
2008-10-30 14:37:56 +00:00
|
|
|
if ($args[0] ne 'stat') {
|
2009-03-28 15:03:36 +00:00
|
|
|
if ($request->{'_disparatetftp'}->[0]) { #reading hint from preprocess_command
|
2009-03-27 22:09:54 +00:00
|
|
|
$sub_req->({command=>['makedhcp'],arg=>['-l'],
|
|
|
|
node=>\@nodes},$callback);
|
|
|
|
} else {
|
2008-10-30 14:37:56 +00:00
|
|
|
$sub_req->({command=>['makedhcp'],
|
|
|
|
node=>\@nodes},$callback);
|
|
|
|
}
|
2009-03-27 22:09:54 +00:00
|
|
|
}
|
2008-06-27 14:35:20 +00:00
|
|
|
|
2007-10-26 22:44:33 +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
|
2009-03-25 02:56:58 +00:00
|
|
|
function. The key is the nodeset status and the value is a pointer
|
|
|
|
to an array of nodes.
|
2008-09-26 23:07:45 +00:00
|
|
|
Returns:
|
|
|
|
(return code, error message)
|
|
|
|
=cut
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
sub getNodesetStates {
|
|
|
|
my $noderef=shift;
|
|
|
|
if ($noderef =~ /xCAT_plugin::pxe/) {
|
|
|
|
$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];
|
2009-03-25 02:56:58 +00:00
|
|
|
if (exists($hashref->{$stat})) {
|
|
|
|
my $pa=$hashref->{$stat};
|
|
|
|
push(@$pa, $node);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$hashref->{$stat}=[$node];
|
|
|
|
}
|
2008-09-26 23:07:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0, "");
|
|
|
|
}
|
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
1;
|