hfi mac address failover code checkin

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9494 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
wanghuaz 2011-05-05 15:41:39 +00:00
parent 8f3f077c52
commit 4208499630
4 changed files with 129 additions and 62 deletions

View File

@ -100,7 +100,7 @@ sub do_rnetboot {
#######################################
# Network specified
#######################################
$cmd.= " -s auto -d auto -m $opt->{m} -S $opt->{S} -G $opt->{G} -C $opt->{C}";
$cmd.= " -s auto -d auto -m \"$opt->{m}\" -S $opt->{S} -G $opt->{G} -C $opt->{C}";
if ( exists( $opt->{o} )) {
$cmd.= " -o";
}

View File

@ -618,15 +618,15 @@ sub mknetboot
if( $useifname && $machash->{$node}->[0] && $machash->{$node}->[0]->{'mac'}) {
# TODO: currently, only "mac" attribute with classic style is used, the "|" delimited string of "macaddress!hostname" format is not used
$mac = $machash->{$node}->[0]->{'mac'};
if ( (index($mac, "|") eq -1) and (index($mac, "!") eq -1) ) {
# if ( (index($mac, "|") eq -1) and (index($mac, "!") eq -1) ) {
#convert to linux format
if ($mac !~ /:/) {
$mac =~s/(..)(..)(..)(..)(..)(..)/$1:$2:$3:$4:$5:$6/;
}
} else {
$callback->({ error=>[ qq{In the "mac" table, the "|" delimited string of "macaddress!hostname" format is not supported by "nodeset <nr> netboot|statelite if installnic/primarynic is set".}], errorcode=>[1]});
return;
}
# } else {
# $callback->({ error=>[ qq{In the "mac" table, the "|" delimited string of "macaddress!hostname" format is not supported by "nodeset <nr> netboot|statelite if installnic/primarynic is set".}], errorcode=>[1]});
# return;
# }
}
if ($useifname && $mac) {
@ -643,7 +643,7 @@ sub mknetboot
} elsif ( $reshash->{$node}->[0] and $reshash->{$node}->[0]->{primarynic} and $reshash->{$node}->[0]->{primarynic} ne "mac") {
$kcmdline .= "netdev=" . $reshash->{$node}->[0]->{primarynic} . " ";
} else {
if ($useifname && $mac) {
if ( $useifname && $mac) {
$kcmdline .= "BOOTIF=" . $mac . " ";
}
}

View File

@ -95,57 +95,123 @@ sub setstate {
unless (-d "$tftpdir/etc") {
mkpath("$tftpdir/etc");
}
open($pcfg,'>',$tftpdir."/etc/".$node);
my $cref=$chainhash{$node}->[0]; #$chaintab->getNodeAttribs($node,['currstate']);
if ($cref->{currstate}) {
print $pcfg "#".$cref->{currstate}."\n";
}
print $pcfg "timeout=5\n";
$normalnodes{$node}=1; #Assume a normal netboot (well, normal dhcp,
my %client_nethash = xCAT::DBobjUtils->getNetwkInfo( [$node] );
if ( $client_nethash{$node}{mgtifname} =~ /hf/ ) {
my $mactab = xCAT::Table->new('mac');
if ($mactab) {
my $ment = $machash{$node}->[0]; #$mactab->getNodeAttribs($node,['mac']);
if ($ment and $ment->{mac}) {
my @macs = split(/\|/,$ment->{mac});
my $count = 0;
foreach my $mac (@macs) {
if ( $mac !~ /!(.*)/) {
my $hostname = $node . "-hf" . $count;
open($pcfg,'>',$tftpdir."/etc/".$hostname);
my $cref=$chainhash{$node}->[0]; #$chaintab->getNodeAttribs($node,['currstate']);
if ($cref->{currstate}) {
print $pcfg "#".$cref->{currstate}."\n";
}
print $pcfg "timeout=5\n";
$normalnodes{$node}=1;
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);
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}) {
my $kcmdline = $kern->{kcmdline};
$kcmdline =~ s/(.*ifname=.*):@macs->[0].*( netdev.*)/$1:$mac$2/g;
print $pcfg "\tappend=\"".$kcmdline."\"\n";
}
close($pcfg);
my $inetn = xCAT::NetworkUtils->getipaddr($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);
}
if ($mac =~ /:/) {
my $tmp = $mac;
$tmp =~ s/(..):(..):(..):(..):(..):(..)/$1-$2-$3-$4-$5-$6/g;
my $pname = "25-" . $tmp;
unlink($tftpdir."/etc/".$pname);
link($tftpdir."/etc/".$hostname,$tftpdir."/etc/".$pname);
}
}
$count = $count + 2;
}
}
}
} else {
open($pcfg,'>',$tftpdir."/etc/".$node);
my $cref=$chainhash{$node}->[0]; #$chaintab->getNodeAttribs($node,['currstate']);
if ($cref->{currstate}) {
print $pcfg "#".$cref->{currstate}."\n";
}
print $pcfg "timeout=5\n";
$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);
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";
# $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);
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 = xCAT::NetworkUtils->getipaddr($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);
}
if ($kern and $kern->{kcmdline}) {
print $pcfg "\tappend=\"".$kern->{kcmdline}."\"\n";
my $ip = xCAT::NetworkUtils->getipaddr($node);
unless ($ip) {
syslog("local1|err","xCAT unable to resolve IP in yaboot plugin");
return;
}
close($pcfg);
my $inetn = xCAT::NetworkUtils->getipaddr($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 = xCAT::NetworkUtils->getipaddr($node);
unless ($ip) {
syslog("local1|err","xCAT unable to resolve IP in yaboot plugin");
return;
}
my $mactab = xCAT::Table->new('mac');
my %ipaddrs;
$ipaddrs{$ip} = 1;
if ($mactab) {
my $ment = $machash{$node}->[0]; #$mactab->getNodeAttribs($node,['mac']);
if ($ment and $ment->{mac}) {
my $mactab = xCAT::Table->new('mac');
my %ipaddrs;
$ipaddrs{$ip} = 1;
if ($mactab) {
my $ment = $machash{$node}->[0]; #$mactab->getNodeAttribs($node,['mac']);
if ($ment and $ment->{mac}) {
my @macs = split(/\|/,$ment->{mac});
foreach (@macs) {
if (/!(.*)/) {
@ -155,15 +221,16 @@ sub setstate {
}
}
}
}
}
# Do not use symbolic link, p5 does not support symbolic link in /tftpboot
# my $hassymlink = eval { symlink("",""); 1 };
foreach $ip (keys %ipaddrs) {
my @ipa=split(/\./,$ip);
my $pname = sprintf("%02x%02x%02x%02x",@ipa);
unlink($tftpdir."/etc/".$pname);
link($tftpdir."/etc/".$node,$tftpdir."/etc/".$pname);
}
}
# Do not use symbolic link, p5 does not support symbolic link in /tftpboot
# my $hassymlink = eval { symlink("",""); 1 };
foreach $ip (keys %ipaddrs) {
my @ipa=split(/\./,$ip);
my $pname = sprintf("%02x%02x%02x%02x",@ipa);
unlink($tftpdir."/etc/".$pname);
link($tftpdir."/etc/".$node,$tftpdir."/etc/".$pname);
}
}
}

View File

@ -2610,7 +2610,7 @@ if { $noboot } { # Display information for all supported adapters
set ping_rc [ping_server $full_path_name_array($i) $phandle_array($i)]
}
set mac_address [get_mac_addr $phandle_array($i)]
if { [string compare -nocase "$mac_address" "$macaddress"] == 0 } {
if { [string first "$mac_address" "$macaddress"] != -1 } {
if { $discovery == 1 } {
if { $adap_type($i) != "hfi-ent" } {
set ping_rc [ping_server $full_path_name_array($i) $phandle_array($i)]