The item of updating pre-defined groups for nodes

This commit is contained in:
zhaoertao 2013-08-15 20:10:50 -07:00
parent 11b99248a9
commit f2b4b14a53
11 changed files with 266 additions and 24 deletions

View File

@ -13,6 +13,7 @@ use xCAT::GlobalDef;
use xCAT::Usage;
use xCAT::NetworkUtils;
use xCAT::FSPUtils;
require xCAT::data::ibmhwtypes;
#use Data::Dumper;
##############################################
@ -391,6 +392,7 @@ sub format_stanza {
#################################
# Add each attribute
#################################
my $mtm = undef;
foreach ( @attribs ) {
my $d = $data[$i++];
@ -401,7 +403,8 @@ sub format_stanza {
} elsif ( /^hwtype$/ ) {
$d = $globalhwtype{$type};
} elsif ( /^groups$/ ) {
$d = "$type,all";
next;
#$d = "$type,all";
} elsif ( /^mgt$/ ) {
$d = $hwtype;
} elsif ( /^cons$/ ) {
@ -414,7 +417,9 @@ sub format_stanza {
} elsif ( /^(mtm|serial)$/ ) {
if ( $type eq "lpar" ) {
$d = undef;
}
} elsif (/^mtm$/) {
$mtm = $d;
}
} elsif (/^side$/) {
unless ( $type =~ /^fsp|bpa$/ ) {
next;
@ -422,6 +427,15 @@ sub format_stanza {
}
$result .= "\t$_=$d\n";
}
my $tmp_groups = "$type,all";
if (defined($mtm)) {
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group($mtm);
if (defined($tmp_pre)) {
$tmp_groups .= ",$tmp_pre";
}
}
$result .= "\tgroups=$tmp_groups\n";
}
return( $result );
}
@ -464,6 +478,7 @@ sub format_xml {
#################################
# Add each attribute
#################################
my $mtm = undef;
foreach ( @attribs ) {
my $d = $data[$i++];
@ -472,7 +487,8 @@ sub format_xml {
} elsif ( /^hwtype$/ ) {
$d = $globalhwtype{$type};
} elsif ( /^groups$/ ) {
$d = "$type,all";
next;
#$d = "$type,all";
} elsif ( /^mgt$/ ) {
$d = $hwtype;
} elsif ( /^cons$/ ) {
@ -484,6 +500,8 @@ sub format_xml {
} elsif ( /^(mtm|serial)$/ ) {
if ( $type eq "lpar" ) {
$d = undef;
} elsif (/^mtm$/) {
$mtm = $d;
}
} elsif (/^side$/) {
unless ( $type =~ /^fsp|bpa$/ ) {
@ -492,6 +510,15 @@ sub format_xml {
}
$href->{Node}->{$_} = $d;
}
my $tmp_groups = "$type,all";
if (defined($mtm)) {
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group($mtm);
if (defined($tmp_pre)) {
$tmp_groups .= ",$tmp_pre";
}
}
$href->{Node}->{groups}=$tmp_groups;
#print Dumper($href);
#################################
# XML encoding

View File

@ -7,6 +7,7 @@ use xCAT::GlobalDef;
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::NetworkUtils;
require xCAT::data::ibmhwtypes;
###########################################
# Factory defaults
@ -168,6 +169,10 @@ sub add_ppc {
# Update nodelist table
###########################
updategroups( $name, $db{nodelist}, $type );
my $tmp_group = xCAT::data::ibmhwtypes::parse_group($model);
if (defined($tmp_group)) {
updategroups($name, $db{nodelist}, $tmp_group);
}
if ( $type =~ /^(fsp|bpa)$/ ) {
$db{nodelist}->setNodeAttribs( $name, {hidden => '1'});
} else {
@ -525,6 +530,10 @@ sub update_node_attribs
if ( $namediff)
{
updategroups( $name, $db->{nodelist}, $type );
my $tmp_group = xCAT::data::ibmhwtypes::parse_group($model);
if (defined($tmp_group)) {
updategroups($name, $db->{nodelist}, $tmp_group);
}
$db->{nodelist}->setNodeAttribs( $name, {status=>$nodelisthash->{status},
appstatus=>$nodelisthash->{appstatus},
primarysn=>$nodelisthash->{primarysn},

View File

@ -5,6 +5,8 @@ use strict;
use Getopt::Long;
use xCAT::PPCcli qw(SUCCESS EXPECT_ERROR RC_ERROR NR_ERROR);
use xCAT::Usage;
use xCAT::TableUtils;
require xCAT::data::ibmhwtypes;
##########################################
@ -59,7 +61,7 @@ sub parse_args {
$Getopt::Long::ignorecase = 0;
Getopt::Long::Configure( "bundling" );
if ( !GetOptions( \%opt, qw(V|verbose) )) {
if ( !GetOptions( \%opt, qw(V|verbose t) )) {
return( usage() );
}
####################################
@ -75,6 +77,9 @@ sub parse_args {
if ( !defined( $cmd )) {
return(usage( "Invalid command: $ARGV[0]" ));
}
if (exists($opt{t}) and $cmd ne "model") {
return(["Option 't' can only work with 'model'."]);
}
####################################
# Check for an extra argument
####################################
@ -411,6 +416,12 @@ sub vpd {
#############################
# Output value
#############################
if ($_ eq 'model' and exists($request->{opt}->{t})) {
my $tmp_pre = xCAT::data::ibmhwtypes::parse_args($data->{$_});
if (defined($tmp_pre)) {
xCAT::TableUtils->updatenodegroups($name, $tmp_pre);
}
}
my $value = "@{$prefix{$_}}[0]: $data->{$_}";
push @result, [$name,$value,$Rc];
}

View File

@ -11,7 +11,7 @@ use xCAT::PPCdb;
use xCAT::GlobalDef;
use xCAT::Usage;
use xCAT::NetworkUtils;
require xCAT::data::ibmhwtypes;
##############################################
# Globals
@ -545,6 +545,7 @@ sub format_stanza {
#################################
# Add each attribute
#################################
my $mtm = undef;
foreach ( @attribs ) {
my $d = $data[$i++];
@ -555,7 +556,8 @@ sub format_stanza {
} elsif ( /^hwtype$/ ) {
$d = $globalhwtype{$type};
} elsif ( /^groups$/ ) {
$d = "$type,all";
next;
#$d = "$type,all";
} elsif ( /^mgt$/ ) {
$d = $hwtype;
} elsif ( /^cons$/ ) {
@ -568,7 +570,9 @@ sub format_stanza {
} elsif ( /^(mtm|serial)$/ ) {
if ( $type eq "lpar" ) {
$d = undef;
}
} elsif (/^mtm$/) {
$mtm = $d;
}
} elsif (/^side$/) {
unless ( $type =~ /^fsp|bpa$/ ) {
next;
@ -576,6 +580,14 @@ sub format_stanza {
}
$result .= "\t$_=$d\n";
}
my $tmp_groups = "$type,all";
if (defined($mtm)) {
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group($mtm);
if (defined($tmp_pre)) {
$tmp_groups .= ",$tmp_pre";
}
}
$result .= "\tgroups=$tmp_groups\n";
}
return( $result );
}
@ -623,6 +635,7 @@ sub format_xml {
#################################
# Add each attribute
#################################
my $mtm = undef;
foreach ( @attribs ) {
my $d = $data[$i++];
@ -631,7 +644,8 @@ sub format_xml {
} elsif ( /^hwtype$/ ) {
$d = $globalhwtype{$type};
} elsif ( /^groups$/ ) {
$d = "$type,all";
next;
#$d = "$type,all";
} elsif ( /^mgt$/ ) {
$d = $hwtype;
} elsif ( /^cons$/ ) {
@ -643,6 +657,8 @@ sub format_xml {
} elsif ( /^(mtm|serial)$/ ) {
if ( $type eq "lpar" ) {
$d = undef;
} elsif (/^mtm$/){
$mtm = $d;
}
} elsif (/^side$/) {
unless ( $type =~ /^fsp|bpa$/ ) {
@ -651,6 +667,14 @@ sub format_xml {
}
$href->{Node}->{$_} = $d;
}
my $tmp_groups = "$type,all";
if (defined($mtm)) {
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group($mtm);
if (defined($tmp_pre)) {
$tmp_groups .= ",$tmp_pre";
}
}
$href->{Node}->{groups}=$tmp_groups;
#################################
# XML encoding
#################################

View File

@ -1735,4 +1735,51 @@ sub getimagenames()
$nodetab->close;
return @imagenames;
}
#-----------------------------------------------------------------------------
=head3 updatenodegroups
Update groups attribute for the specified node
Arguments:
node
tabhd: the handler of 'nodelist' table,
groups: the groups attribute need to be merged.
Can be an array or string.
Globals:
none
Error:
Example:
xCAT::TableUtils->updatenodegroups($node, $tab, $groups);
=cut
#-----------------------------------------------------------------------------
sub updatenodegroups {
my ($class, $node, $tabhd, $groups) = @_;
if (!$groups) {
$groups = $tabhd;
$tabhd = xCAT::Table->new('nodelist');
unless ($tabhd) {
xCAT::MsgUtils->message("E", " Could not read the nodelist table\n");
return;
}
}
my ($ent) = $tabhd->getNodeAttribs($node, ['groups']);
my @list = qw(all);
if (defined($ent) and $ent->{groups}) {
push @list, split(/,/,$ent->{groups});
}
if (ref($groups) eq 'ARRAY') {
push @list, @$groups;
} else {
push @list, split(/,/,$groups);
}
my %saw;
@saw{@list} = ();
@list = keys %saw;
$tabhd->setNodeAttribs($node, {groups=>join(",",@list)});
}
1;

View File

@ -72,16 +72,16 @@ my %usage = (
rinv <noderange> [all|model|serial] [-V|--verbose]
rinv [-h|--help|-v|--version]
BMC specific:
rinv <noderange> [vpd|mprom|deviceid|uuid|guid]
rinv <noderange> [mprom|deviceid|uuid|guid|vpd [-t]|all [-t]]
MPA specific:
rinv <noderange> [firm|bios|diag|mprom|sprom|mparom|mac|mtm]
rinv <noderange> [firm|bios|diag|mprom|sprom|mparom|mac|mtm [-t]]
PPC specific(with HMC):
rinv <noderange> [bus|config|serial|model|firm|all]
rinv <noderange> [all|bus|config|serial|model|firm [-t]]
PPC specific(using Direct FSP Management):
rinv <noderange> [firm]
rinv <noderange> [deconfig [-x]]
Blade specific:
rinv <noderange> [mtm|serial|mac|bios|diag|mprom|mparom|firm|all]
rinv <noderange> [all|serial|mac|bios|diag|mprom|mparom|firm|mtm [-t]]
IBM Flex System Compute Node specific:
rinv <noderange> [firm]
VMware specific:

View File

@ -0,0 +1,43 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
package xCAT::data::ibmhwtypes;
require Exporter;
@EXPORT_OK=qw(parse_group mt2group);
use Data::Dumper;
my %groups2mtm = (
"x3250" => ["2583","4251","4252"],
"x3550" => ["7914","7944","7946"],
"x3650" => ["7915","7945"],
"dx360" => [],
"x220" => ["7906"],
"x240" => ["8737","7863"],
"x440" => ["7917"],
"p260" => ["7895"], #789522X, 789523X
"p460" => [], #789542X
"p470" => ["7954"],
);
%mt2group = ();
foreach my $group (keys %groups2mtm) {
foreach my $mtm (@{$groups2mtm{$group}}) {
$mt2group{$mtm} = $group;
}
}
sub parse_group {
my $mtm = shift;
if ($mtm =~ /xCAT::data/) {
$mtm = shift;
}
if ($mtm =~ /^(\w{4})/) {
$mt = $1;
if ($mt eq "7895" and $mtm =~ /789542X/i) {
return "p460";
}
return $mt2group{$mt};
}
return undef;
}
1;

View File

@ -28,6 +28,7 @@ use xCAT::GlobalDef;
use xCAT_monitoring::monitorctrl;
use strict;
use LWP;
require xCAT::data::ibmhwtypes;
#use warnings;
my %mm_comm_pids;
@ -1773,6 +1774,7 @@ sub rscan_xml {
my $href = {
Node => { }
};
my $mtm = undef;
foreach ( @rscan_attribs ) {
my $d = $data[$i++];
@ -1789,6 +1791,7 @@ sub rscan_xml {
}
} elsif ( /^groups$/ ) {
$d = "$type,all";
$ignore = 1;
} elsif ( /^mgt$/ ) {
if ($origtype eq "ppcblade") {
$d = "fsp";
@ -1831,13 +1834,23 @@ sub rscan_xml {
} else {
$ignore = 1;
}
} elsif (/^mtm$/) {
$d =~ /^(\w{4})/;
$mtm = $1;
}
if (!$ignore) {
$href->{Node}->{$_} = $d;
}
}
my $tmp_groups = "$type,all";
if (defined($mtm)) {
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group($mtm);
if (defined($tmp_pre)) {
$tmp_groups .= ",$tmp_pre";
}
}
$href->{Node}->{groups} = $tmp_groups;
$xml.= XMLout($href,NoAttr=>1,KeyAttr=>[],RootName=>undef);
}
return( $xml );
@ -1872,7 +1885,7 @@ sub rscan_stanza {
$objname = $data[1];
}
$result .= "$objname:\n\tobjtype=node\n";
my $mtm = undef;
foreach ( @rscan_attribs ) {
my $d = $data[$i++];
@ -1889,6 +1902,7 @@ sub rscan_stanza {
}
} elsif ( /^groups$/ ) {
$d = "$type,all";
$ignore = 1;
} elsif ( /^mgt$/ ) {
if ($origtype eq "ppcblade") {
$d = "fsp";
@ -1931,12 +1945,23 @@ sub rscan_stanza {
} else {
$ignore = 1;
}
} elsif (/^mtm$/) {
$d =~ /^(\w{4})/;
$mtm = $1;
}
if (!$ignore) {
$result .= "\t$_=$d\n";
}
}
my $tmp_groups = "$type,all";
if (defined ($mtm)) {
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group($mtm);
if (defined ($tmp_pre)) {
$tmp_groups .= ",$tmp_pre";
}
}
$result .= "\tgroups=$tmp_groups\n";
}
return( $result );
}
@ -2246,6 +2271,13 @@ sub inv {
}
}
}
if ($updatetable and $updatehash{mtm}) {
#updatenodegroups
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group($updatehash{mtm}) ;
if (defined($tmp_pre)) {
xCAT::TableUtils->updatenodegroups($currnode, $tmp_pre);
}
}
if ($updatetable and keys %updatehash) {
my $vpdtab = xCAT::Table->new('vpd');
$vpdtab->setNodeAttribs($currnode,\%updatehash);
@ -4388,6 +4420,12 @@ sub process_request {
unless ($node) {
return 1; #failure
}
if ($request->{mtm} and $request->{mtm} =~ /^(\w{4})/) {
my $group = xCAT::data::ibmhwtypes::parse_group($request->{mtm});
if (defined($group)) {
xCAT::TableUtils->updatenodegroups($node, $group);
}
}
if ($mac) {
my $mactab = xCAT::Table->new('mac',-create=>1);
$mactab->setNodeAttribs($macmap{$mac},{mac=>$mac});

View File

@ -34,6 +34,7 @@ my $iem_support;
my $vpdhash;
my %allerrornodes=();
my $global_sessdata;
require xCAT::data::ibmhwtypes;
eval {
require IBM::EnergyManager;
@ -1568,6 +1569,11 @@ sub inv {
sub fru_initted {
my $sessdata = shift;
my $key;
my @args = @{$sessdata->{extraargs}};
my $up_group = undef;
if (grep /-t/, @args) {
$up_group = '1';
}
my @types = @{$sessdata->{invtypes}};
my $format = "%-20s %s";
@ -1576,11 +1582,17 @@ sub fru_initted {
my $type;
foreach $type (split /,/,$fru->rec_type) {
if(grep {$_ eq $type} @types) {
my $bmcifo="";
if ($sessdata->{bmcnum} != 1) {
$bmcifo=" on BMC ".$sessdata->{bmcnum};
}
xCAT::SvrUtils::sendmsg(sprintf($format.$bmcifo,$sessdata->{fru_hash}->{$key}->desc . ":",$sessdata->{fru_hash}->{$key}->value),$callback,$sessdata->{node},%allerrornodes);
my $bmcifo="";
if ($sessdata->{bmcnum} != 1) {
$bmcifo=" on BMC ".$sessdata->{bmcnum};
}
xCAT::SvrUtils::sendmsg(sprintf($format.$bmcifo,$sessdata->{fru_hash}->{$key}->desc . ":",$sessdata->{fru_hash}->{$key}->value),$callback,$sessdata->{node},%allerrornodes);
if ($up_group and $type eq "model" and $fru->desc =~ /MTM/) {
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group($fru->value);
if (defined($tmp_pre)) {
xCAT::TableUtils->updatenodegroups($sessdata->{node}, $tmp_pre);
}
}
last;
}
}
@ -6001,6 +6013,14 @@ sub preprocess_request {
my (@bmcnodes, @nohandle);
xCAT::Utils->filter_nodes($request, undef, undef, \@bmcnodes, \@nohandle);
$realnoderange = \@bmcnodes;
} elsif ($command eq "rinv") {
if ($exargs[0] eq "-t" and $#exargs == 0) {
unshift @{$request->{arg}}, 'all';
} elsif ((grep /-t/, @exargs) and !(grep /(all|vpd)/, @exargs) ) {
$callback->({errorcode=>[1],error=>["option '-t' can only work with 'all' or 'vpd'"]});
$request = {};
return 0;
}
}
if (!$realnoderange) {

View File

@ -20,6 +20,7 @@ use xCAT::MacMap;
use xCAT::IMMUtils;
use xCAT_plugin::blade;
use xCAT::SLP;
require xCAT::data::ibmhwtypes;
my $mpahash;
@ -1401,11 +1402,18 @@ sub xCATdB {
my $id = ($type =~ /bpa|frame/) ? $frameid:$cageid;
my $hidden = ($type =~ /bpa|fsp/)? 1:0;
my $groups = lc($type).",all";
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group($model);
if (defined($tmp_pre)) {
$groups .= ",$tmp_pre";
}
########################################
# Write result to every tables,
########################################
if ( $type =~ /^bpa|fsp|cec|frame$/ ) {
$nodelisthash{$hostname} = {groups=>"$type,all", hidden=>$hidden};
#$nodelisthash{$hostname} = {groups=>"$type,all", hidden=>$hidden};
$nodelisthash{$hostname} = {groups=>$groups, hidden=>$hidden};
$ppchash{$hostname} = {id=>$id, parent=>$parent, hcp=>$hostname, nodetype=>$globalhwtype{$type}};
$vpdhash{$hostname} = {mtm=>$model, serial=>$serial, side=>$side};
$nodehmhash{$hostname} = {mgt=>$globalmgt{$type}};
@ -1416,7 +1424,7 @@ sub xCATdB {
my @data = ($type, $model, $serial, $side, $ip, $frameid, $cageid, $parent, $mac);
xCAT::PPCdb::add_systemX( $type, $hostname, \@data );
} elsif ( $type =~ /^(hmc|ivm)$/ ) {
$nodelisthash{$hostname} = {groups=>"$type,all", hidden=>$hidden};
$nodelisthash{$hostname} = {groups=>$groups, hidden=>$hidden};
$ppchash{$hostname} = {nodetype=>$globalhwtype{$type}};
$vpdhash{$hostname} = {mtm=>$model, serial=>$serial};
$nodetypehash{$hostname} = {nodetype=>$globalnodetype{$type}};
@ -1424,7 +1432,7 @@ sub xCATdB {
$hostshash{$hostname} = {ip=>$ip};
$machash{$hostname} = {mac=>$mac};
}elsif ($type =~ /^cmm$/){
$nodelisthash{$hostname} = {groups=>"cmm,all", hidden=>$hidden};
$nodelisthash{$hostname} = {groups=>$groups, hidden=>$hidden};
$vpdhash{$hostname} = {mtm=>$model, serial=>$serial};
$nodetypehash{$hostname} = {nodetype=>$globalnodetype{$type}};
$nodehmhash{$hostname} = {mgt=>"blade"};
@ -1474,6 +1482,12 @@ sub format_stanza {
$ip = $2;
}
my $type = ${$outhash->{$name}}{type};
my $groups = "$type,all";
my $tmp_pre = xCAT::data::ibmhwtypes::parse_group(${$outhash->{$name}}{mtm});
if (defined($tmp_pre)) {
$groups .= ",$tmp_pre";
}
#################################
# Node attributes
@ -1490,7 +1504,8 @@ sub format_stanza {
if ($type =~ /^fsp|bpa|cmm$/) {
$result .= "\tside=${$outhash->{$name}}{side}\n";
}
$result .= "\tgroups=$type,all\n";
#$result .= "\tgroups=$type,all\n";
$result .= "\tgroups=$groups\n";
$result .= "\tmgt=$globalmgt{$type}\n";
if ($type =~ /^fsp|bpa|frame|cec$/) {
$result .= "\tid=${$outhash->{$name}}{$globalid{$type}}\n";

View File

@ -27,6 +27,7 @@ use xCAT::NetworkUtils;
use xCAT::MsgUtils;
use xCAT::DiscoveryUtils;
use xCAT::NodeRange qw/noderange/;
require xCAT::data::ibmhwtypes;
use Time::HiRes qw(gettimeofday sleep);
@ -272,7 +273,14 @@ sub findme {
$nltab->setNodeAttribs($node, {groups=>"all"});
}
}
# update node groups with pre-defined groups
if (defined($param{'mtm'})){
my @list = ();
my $tmp_group = xCAT::data::ibmhwtypes::parse_group($param{'mtm'});
if (defined($tmp_group)) {
xCAT::TableUtils->updatenodegroups($node, $nltab, $tmp_group);
}
}
# set the mgt for the node
my $hmtab = xCAT::Table->new('nodehm');
unless ($hmtab) {