merge code from branch 2.8

This commit is contained in:
Jia Zhao 2014-05-29 14:30:09 +08:00
parent d26a616680
commit 44e3271119
2 changed files with 152 additions and 5 deletions

View File

@ -500,6 +500,7 @@ sub setCFMPkglistFile {
Arguments:
$imagename - the specified linuximage name
@curospkgs - the currently selected OS packages list
$mode - using Fuzzy Matching or Exact Matching to check packages
Returns:
0 - update successfully
1 - update failed
@ -509,13 +510,22 @@ sub setCFMPkglistFile {
none
Example:
my $ret = CAT::CFMUtils->updateCFMPkglistFile($imagename, @cur_selected_pkgs);
my $ret = CAT::CFMUtils->updateCFMPkglistFile($imagename, @cur_selected_pkgs, 1);
=cut
#-----------------------------------------------------------------------------
sub updateCFMPkglistFile {
my ($class, $img, $ospkgs) = @_;
my ($class, $img, $ospkgs, $mode) = @_;
if(defined($mode)){
# Exact Matching
$mode = 1;
}else {
# Fuzzy Matching
$mode = 0;
}
my @cur_selected = @$ospkgs;
my $cfmpkglist = "/install/osimages/$img/pkglist.cfm";
@ -549,6 +559,14 @@ sub updateCFMPkglistFile {
my @selected = @$selected_ref;
@basepkgs = xCAT::CFMUtils->arrayops("U", \@basepkgs, \@selected);
}
# Fuzzy Matching
if (not $mode){
my ($ref1, $ref2, $ref3) = xCAT::CFMUtils->updateSelectedPkgs(\@pre_selected, \@pre_removed, \@cur_selected);
@pre_selected = @$ref1;
@pre_removed = @$ref2;
@cur_selected = @$ref3;
}
# get diff between previous and current selected OS packages lists
my @diff = xCAT::CFMUtils->getPkgsDiff(\@pre_selected, \@cur_selected);
@ -661,6 +679,48 @@ sub getPreOSpkgsList {
return (\@selected, \@removed);
}
#-----------------------------------------------------------------------------
=head3 getPreBaseOSpkgsList
Get previously selected and removed base OS packages lists from pkglist file. Packages named with "example.xxx" should be the base name "example"
Arguments:
$ospkglist - the path for ospkglist file
Returns:
refs for selected and removed OS packages arrays
Globals:
none
Error:
none
Example:
my $pre_selected_ref = xCAT::CFMUtils->getPreOSpkgsList($ospkglist);
=cut
#-----------------------------------------------------------------------------
sub getPreBaseOSpkgsList {
my ($class, $pkglist) = @_;
my ($pre_selected_ref, $pre_removed_ref) = xCAT::CFMUtils->getPreOSpkgsList($pkglist);
my %pre_selected_hash = ();
foreach (@$pre_selected_ref) {
my @names = split(/\./, $_);
my $basename = $names[0];
if ($_ =~ /^$basename\.([^\.]+)$/) {
$pre_selected_hash{$basename} = 1;
}else {
$pre_selected_hash{$_} = 1;
}
}
@pre_selected = keys %pre_selected_hash;
return \@pre_selected;
}
#-----------------------------------------------------------------------------
=head3 getPkgsDiff
@ -819,3 +879,66 @@ sub arrayops {
#return (\@union, \@intersection, \@difference);
}
#-----------------------------------------------------------------------------
=head3 updateSelectedPkgs
Update previous selected, previous removed and current selected packages based on fuzzy matching rules. Packages named with "example.i686" should be same with package "example"
Arguments:
\@pre_selected - reference to previous selected packages
\@pre_removed - reference to previous removed packages
\@cur_selected - reference to current selected packages
Returns:
new previous selected, previous removed, current selected packages
Globals:
none
Error:
none
Example:
my ($ref1, $ref2, $ref3) = xCAT::CFMUtils->arrayops(\@pre_selected, \@pre_removed, \@cur_selected);
=cut
#-----------------------------------------------------------------------------
sub updateSelectedPkgs() {
my ($class, $pre_selected_ref, $pre_removed_ref, $cur_selected_ref) = @_;
my %pre_selected_hash = map{$_ => 1} @$pre_selected_ref;
my %pre_removed_hash = map{$_ => 1} @$pre_removed_ref;
my %cur_selected_hash = map{$_ => 1} @$cur_selected_ref;
my %new_pre_selected_hash = %pre_selected_hash;
my %new_pre_removed_hash = %pre_removed_hash;
my %new_cur_selected_hash = %cur_selected_hash;
foreach (keys %cur_selected_hash) {
my $father = $_;
my $flag = 0;
foreach (keys %pre_selected_hash) {
my $child = $_;
if ($child =~ /^$father\.([^\.]+)$/) {
$new_cur_selected_hash{$child} = 1;
$flag = 1;
}
}
if ($flag and not exists $pre_selected_hash{$father}){
delete $new_cur_selected_hash{$father} if exists $new_cur_selected_hash{$father};
}
foreach (keys %pre_removed_hash) {
my $child = $_;
if ($child =~ /^$father\.([^\.]+)$/) {
delete $new_pre_removed_hash{$child} if exists $new_pre_removed_hash{$child};
}
}
}
my @new_cur_selected = keys %new_cur_selected_hash;
my @new_pre_selected = keys %new_pre_selected_hash;
my @new_pre_removed = keys %new_pre_removed_hash;
return (\@new_pre_selected, \@new_pre_removed, \@new_cur_selected);
}

View File

@ -771,10 +771,30 @@ Usage:
}
# If network profile specified. Need re-generate IPs for all nodess again.
# As new design, ignore BMC/FSP NIC while reinstall nodes
if(exists $args_dict{'networkprofile'}){
my $newNetProfileName = $args_dict{'networkprofile'};
my $oldNetProfileName = $nodeoldprofiles{'networkprofile'};
my $newNicsRef = xCAT::ProfiledNodeUtils->get_nodes_nic_attrs([$newNetProfileName])->{$newNetProfileName};
my $oldNicsRef = xCAT::ProfiledNodeUtils->get_nodes_nic_attrs([$oldNetProfileName])->{$oldNetProfileName};
my %updateNicsHash = ();
foreach my $newNic (keys %$newNicsRef) {
if ($newNicsRef->{$newNic}->{'type'} ne 'BMC' and $newNicsRef->{$newNic}->{'type'} ne 'FSP'){
$updateNicsHash{$newNic} = 1;
}
}
foreach my $oldNic (keys %$oldNicsRef) {
if ($oldNicsRef->{$oldNic}->{'type'} ne 'BMC' and $oldNicsRef->{$oldNic}->{'type'} ne 'FSP'){
$updateNicsHash{$oldNic} = 1;
}
}
my $updateNics = join(",", keys %updateNicsHash);
setrsp_progress("Regenerate IP addresses for nodes...");
$retref = "";
$retref = xCAT::Utils->runxcmd({command=>["noderegenips"], node=>$nodes, sequential=>[1]}, $request_command, 0, 2);
$retref = xCAT::Utils->runxcmd({command=>["noderegenips"], node=>$nodes, arg=>["nics=$updateNics"], sequential=>[1]}, $request_command, 0, 2);
$retstrref = parse_runxcmd_ret($retref);
if ($::RUNCMD_RC != 0){
setrsp_progress("Warning: failed to generate IPs for nodes.");
@ -843,6 +863,7 @@ Usage:
$netProfileNicsRef = xCAT::ProfiledNodeUtils->get_nodes_nic_attrs([$netProfileName]);
my $nicsref = $netProfileNicsRef->{$netProfileName};
my @nicslist = keys %$nicsref;
#3. validate specified nics
if(exists $args_dict{'nics'}){
@updateNics = split(",", $args_dict{'nics'});
@ -910,7 +931,9 @@ Usage:
unless (grep {$_ eq $nicname} @updateNics){
# if the nic not specified, just keep the old IP&NIC record in nics table.
my $oldip = $nodesNicsRef->{$node}->{$nicname}->{"ip"};
$nicipsAttr{$node}{nicips} .= $nicname."!".$oldip.",";
if ($oldip) {
$nicipsAttr{$node}{nicips} .= $nicname."!".$oldip.",";
}
}else{
my $ipsref = $freeIPsHash{$nicname};
my $nextip = shift @$ipsref;
@ -932,7 +955,7 @@ Usage:
}
}
}
#8. Update database.
setrsp_progress("Updating database records...");
my $nicstab = xCAT::Table->new('nics',-create=>1);
@ -2120,6 +2143,7 @@ sub validate_node_entry{
$errmsg .= "MAC address $node_entry{$_} is invalid. You must use a valid MAC address.\n";
}else{
$allmacs{$node_entry{$_}} = 0;
$allmacsupper{uc($node_entry{$_})} = 0;
}
}elsif ($_ eq "ip"){
if (exists $allips{$node_entry{$_}}){