add -u to rscan
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4618 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
d3897c07b1
commit
6eeeb45ffe
@ -166,6 +166,250 @@ sub add_ppc {
|
||||
return undef;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Update nodes in the xCAT databases
|
||||
##########################################################################
|
||||
sub update_ppc {
|
||||
|
||||
my $hwtype = shift;
|
||||
my $values = shift;
|
||||
my $not_overwrite = shift;
|
||||
my @tabs = qw(ppc vpd nodehm nodelist nodetype ppcdirect);
|
||||
my %db = ();
|
||||
my %nodetype = (
|
||||
fsp => $::NODETYPE_FSP,
|
||||
bpa => $::NODETYPE_BPA,
|
||||
lpar =>"$::NODETYPE_LPAR,$::NODETYPE_OSI",
|
||||
hmc => $::NODETYPE_HMC,
|
||||
ivm => $::NODETYPE_IVM,
|
||||
);
|
||||
my @update_list = ();
|
||||
|
||||
###################################
|
||||
# Open database needed
|
||||
###################################
|
||||
foreach ( @tabs ) {
|
||||
$db{$_} = xCAT::Table->new( $_, -create=>1, -autocommit=>0 );
|
||||
if ( !$db{$_} ) {
|
||||
return( "Error opening '$_'" );
|
||||
}
|
||||
}
|
||||
my @vpdlist = $db{vpd}->getAllNodeAttribs(['node','serial','mtm']);
|
||||
my @ppclist = $db{ppc}->getAllNodeAttribs(['node','hcp','id',
|
||||
'pprofile','parent','supernode',
|
||||
'comments', 'disable']);
|
||||
###################################
|
||||
# Update FSP in tables
|
||||
###################################
|
||||
foreach my $value ( @$values ) {
|
||||
my ($type,
|
||||
$name,
|
||||
$id,
|
||||
$model,
|
||||
$serial,
|
||||
$server,
|
||||
$pprofile,
|
||||
$parent,
|
||||
$ips ) = split /,/, $value;
|
||||
|
||||
next if ( $type ne 'fsp' );
|
||||
|
||||
my $predefined_node = undef;
|
||||
foreach my $vpdent (@vpdlist)
|
||||
{
|
||||
if ( $vpdent->{mtm} eq $model && $vpdent->{serial} eq $serial)
|
||||
{
|
||||
$predefined_node = $vpdent->{node};
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
next if ( !$predefined_node);
|
||||
|
||||
if ( update_node_attribs($hwtype, $type, $name, $id, $model, $serial,
|
||||
$server, $pprofile, $parent, $ips,
|
||||
\%db, $predefined_node, \@ppclist))
|
||||
{
|
||||
push @update_list, $value;
|
||||
}
|
||||
}
|
||||
|
||||
###################################
|
||||
# Update BPA in tables
|
||||
###################################
|
||||
foreach my $value ( @$values ) {
|
||||
my ($type,
|
||||
$name,
|
||||
$id,
|
||||
$model,
|
||||
$serial,
|
||||
$server,
|
||||
$pprofile,
|
||||
$parent,
|
||||
$ips ) = split /,/;
|
||||
|
||||
next if ( $type ne 'bpa');
|
||||
|
||||
my $predefined_node = undef;
|
||||
foreach my $vpdent (@vpdlist)
|
||||
{
|
||||
if ( $vpdent->{mtm} eq $model && $vpdent->{serial} eq $serial)
|
||||
{
|
||||
$predefined_node = $vpdent->{node};
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
next if ( !$predefined_node);
|
||||
|
||||
if (update_node_attribs($hwtype, $type, $name, $id, $model, $serial,
|
||||
$server, $pprofile, $parent, $ips,
|
||||
\%db, $predefined_node, \@ppclist))
|
||||
{
|
||||
push @update_list, $value;
|
||||
}
|
||||
}
|
||||
|
||||
###################################
|
||||
# Commit changes
|
||||
###################################
|
||||
foreach ( @tabs ) {
|
||||
if ( exists( $db{$_}{commit} )) {
|
||||
$db{$_}->commit;
|
||||
}
|
||||
}
|
||||
return \@update_list;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Update one node in the xCAT databases
|
||||
##########################################################################
|
||||
sub update_node_attribs
|
||||
{
|
||||
my $mgt = shift;
|
||||
my $type = shift;
|
||||
my $name = shift;
|
||||
my $id = shift;
|
||||
my $model = shift;
|
||||
my $serial = shift;
|
||||
my $server = shift;
|
||||
my $pprofile = shift;
|
||||
my $parent = shift;
|
||||
my $ips = shift;
|
||||
my $db = shift;
|
||||
my $predefined_node = shift;
|
||||
my $ppclist = shift;
|
||||
|
||||
my $updated = undef;
|
||||
my $namediff = $name ne $predefined_node;
|
||||
my $key_col = { node=>$predefined_node};
|
||||
|
||||
#############################
|
||||
# update vpd table
|
||||
#############################
|
||||
my $vpdhash = $db->{vpd}->getNodeAttribs( $name, [qw(mtm serial)]);
|
||||
if ( $model ne $vpdhash->{mtm} or $serial ne $vpdhash->{serial} or $namediff)
|
||||
{
|
||||
$db->{vpd}->delEntries( $key_col) if ( $namediff);
|
||||
$db->{vpd}->setNodeAttribs( $name, { mtm=>$model, serial=>$serial});
|
||||
$db->{vpd}->{commit} = 1;
|
||||
$updated = 1;
|
||||
}
|
||||
|
||||
###########################
|
||||
# Update ppcdirect table
|
||||
###########################
|
||||
my $pwhash = $db->{ppcdirect}->getNodeAttribs( $predefined_node, [qw(username password comments disable)]);
|
||||
if ( $pwhash)
|
||||
{
|
||||
if ( $namediff)
|
||||
{
|
||||
$db->{ppcdirect}->delEntries( {hcp=>$predefined_node}) if ( $namediff);;
|
||||
$db->{ppcdirect}->setAttribs({hcp=>$name},
|
||||
{username=>$pwhash->{username},
|
||||
password=>$pwhash->{password},
|
||||
comments=>$pwhash->{comments},
|
||||
disable=>$pwhash->{disable}});
|
||||
$db->{vpd}->{commit} = 1;
|
||||
$updated = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#############################
|
||||
# update ppc table
|
||||
#############################
|
||||
my $ppchash = $db->{ppc}->getNodeAttribs( $name, [qw(hcp id pprofile parent)]);
|
||||
if ( $server ne $ppchash->{hcp} or
|
||||
$id ne $ppchash->{id} or
|
||||
$pprofile ne $ppchash->{pprofile} or
|
||||
$parent ne $ppchash->{parent} or
|
||||
$namediff)
|
||||
{
|
||||
$db->{ppc}->delEntries( $key_col) if ( $namediff);
|
||||
$db->{ppc}->setNodeAttribs( $name,
|
||||
{ hcp=>$server,
|
||||
id=>$id,
|
||||
pprofile=>$pprofile,
|
||||
parent=>$parent
|
||||
});
|
||||
if ( $namediff)
|
||||
{
|
||||
for my $ppcent (@$ppclist)
|
||||
{
|
||||
next if ($ppcent->{node} eq $predefined_node);
|
||||
if ($ppcent->{parent} eq $predefined_node)
|
||||
{
|
||||
$db->{ppc}->setNodeAttribs( $ppcent->{node}, {parent=>$name});
|
||||
}
|
||||
}
|
||||
}
|
||||
$db->{ppc}->{commit} = 1;
|
||||
$updated = 1;
|
||||
}
|
||||
|
||||
###########################
|
||||
# Update nodehm table
|
||||
###########################
|
||||
my $nodehmhash = $db->{nodehm}->getNodeAttribs( $name, [qw(mgt)]);
|
||||
if ( $mgt ne $nodehmhash->{mgt} or $namediff)
|
||||
{
|
||||
$db->{nodehm}->delEntries( $key_col) if ( $namediff);
|
||||
$db->{nodehm}->setNodeAttribs( $name, {mgt=>$mgt} );
|
||||
$db->{nodehm}->{commit} = 1;
|
||||
$updated = 1;
|
||||
}
|
||||
|
||||
###########################
|
||||
# Update nodetype table
|
||||
###########################
|
||||
my $nodetypehash = $db->{nodetype}->getNodeAttribs( $name, [qw(nodetype)]);
|
||||
if ( $type ne $nodetypehash->{nodetype} or $namediff)
|
||||
{
|
||||
$db->{nodetype}->delEntries( $key_col) if ( $namediff);
|
||||
$db->{nodetype}->setNodeAttribs( $name,{nodetype=>$type} );
|
||||
$db->{nodetype}->{commit} = 1;
|
||||
$updated = 1;
|
||||
}
|
||||
|
||||
###########################
|
||||
# Update nodelist table
|
||||
###########################
|
||||
my $nodelisthash = $db->{nodelist}->getNodeAttribs( $name, [qw(groups status appstatus primarysn comments disable)]);
|
||||
if ( $namediff)
|
||||
{
|
||||
updategroups( $name, $db->{nodelist}, $type );
|
||||
$db->{nodelist}->setNodeAttribs( $name, {status=>$nodelisthash->{status},
|
||||
appstatus=>$nodelisthash->{appstatus},
|
||||
primarysn=>$nodelisthash->{primarysn},
|
||||
comments=>$nodelisthash->{comments},
|
||||
disable=>$nodelisthash->{disable}
|
||||
});
|
||||
$db->{nodelist}->delEntries( $key_col);
|
||||
$db->{nodelist}->{commit} = 1;
|
||||
$updated = 1;
|
||||
}
|
||||
return $updated;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Updates the nodelist.groups attribute
|
||||
|
@ -64,7 +64,7 @@ sub parse_args {
|
||||
$Getopt::Long::ignorecase = 0;
|
||||
Getopt::Long::Configure( "bundling" );
|
||||
|
||||
if ( !GetOptions( \%opt, qw(V|Verbose w x z) )){
|
||||
if ( !GetOptions( \%opt, qw(V|Verbose u w x z) )){
|
||||
return( usage() );
|
||||
}
|
||||
####################################
|
||||
@ -85,6 +85,12 @@ sub parse_args {
|
||||
if (( exists($opt{x}) + exists($opt{z})) > 1 ) {
|
||||
return( usage() );
|
||||
}
|
||||
#############################################
|
||||
# Check for mutually-exclusive flags
|
||||
#############################################
|
||||
if (( exists($opt{u}) + exists($opt{w})) > 1 ) {
|
||||
return(usage( "Flag -u cannot be used with flag -w"));
|
||||
}
|
||||
####################################
|
||||
# No operands - add command name
|
||||
####################################
|
||||
@ -347,19 +353,36 @@ sub format_output {
|
||||
my @val = grep( !/^#.*: ERROR /, @$values );
|
||||
xCAT::PPCdb::add_ppc( $hwtype, \@val );
|
||||
}
|
||||
|
||||
###########################################
|
||||
# -u flag for write to xCat database
|
||||
###########################################
|
||||
if ( exists( $opt->{u} )) {
|
||||
#######################################
|
||||
# Strip errors for results
|
||||
#######################################
|
||||
my @val = grep( !/^#.*: ERROR /, @$values );
|
||||
$values = xCAT::PPCdb::update_ppc( $hwtype, \@val );
|
||||
if ( exists( $opt->{x} ) or exists( $opt->{z} ))
|
||||
{
|
||||
unshift @$values, "hmc";
|
||||
}
|
||||
}
|
||||
|
||||
###########################################
|
||||
# -x flag for xml format
|
||||
###########################################
|
||||
if ( exists( $opt->{x} )) {
|
||||
$result = format_xml( $hwtype, $values );
|
||||
$result .= format_xml( $hwtype, $values );
|
||||
}
|
||||
###########################################
|
||||
# -z flag for stanza format
|
||||
###########################################
|
||||
elsif ( exists( $opt->{z} )) {
|
||||
$result = format_stanza( $hwtype, $values );
|
||||
$result .= format_stanza( $hwtype, $values );
|
||||
}
|
||||
else {
|
||||
$result = sprintf( "#Updated following nodes:\n") if ( exists( $opt->{u}));
|
||||
#######################################
|
||||
# Get longest name for formatting
|
||||
#######################################
|
||||
@ -433,6 +456,7 @@ sub format_stanza {
|
||||
|
||||
my $hwtype = shift;
|
||||
my $values = shift;
|
||||
|
||||
my $result;
|
||||
|
||||
#####################################
|
||||
|
@ -69,7 +69,7 @@ my %usage = (
|
||||
"Usage: rbootseq <noderange> [hd0|hd1|hd2|hd3|net|iscsi|usbflash|floppy|none],...
|
||||
rbootseq [-h|--help|-v|--version]",
|
||||
"rscan" =>
|
||||
"Usage: rscan <noderange> [-w][-x|-z] [-V|--verbose]
|
||||
"Usage: rscan <noderange> [-u][-w][-x|-z] [-V|--verbose]
|
||||
rscan [-h|--help|-v|--version]",
|
||||
"rspconfig" =>
|
||||
"Usage:
|
||||
|
@ -8,14 +8,14 @@ I<rscan [-h|--help]>
|
||||
|
||||
I<rscan [-v|--version]>
|
||||
|
||||
I<rscan [-V|--verbose] noderange [-w][-x|-z]>
|
||||
I<rscan [-V|--verbose] noderange [-u][-w][-x|-z]>
|
||||
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
The rscan command lists hardware information for each node managed by the hardware control points specified in noderange.
|
||||
|
||||
Note that the first line of the output always contains information about the hardware control point itself. When using the rscan command to generate output for HMC or IVM hardware control points, note that FSPs and BPAs are included in the output.
|
||||
Note: except running this command with flag -u, the first line of the output always contains information about the hardware control point itself. When using the rscan command to generate output for HMC or IVM hardware control points, note that FSPs and BPAs are included in the output.
|
||||
|
||||
|
||||
|
||||
@ -29,6 +29,8 @@ B<-v> Command Version.
|
||||
|
||||
B<-V> Verbose output.
|
||||
|
||||
B<-u> Update node definition in xCAT database and print out updated nodes. It updates the existing nodes that have the same mtms and serial as the nodes managed by specified hardware control point. For a CEC and frame node, if the node name is not as same as the managed system name on hardware control point, this flag will update the node name to managed system name. In this release, it can only update CEC and Frame node definitions.
|
||||
|
||||
B<-w> Writes output to xCAT database.
|
||||
|
||||
B<-x> XML format.
|
||||
@ -168,6 +170,16 @@ Output is similar to:
|
||||
mgt=hmc
|
||||
cons=hmc
|
||||
|
||||
4. To update definitions of nodes, which is managed by hmc03, enter:
|
||||
|
||||
I<rscan hmc03 -u>
|
||||
|
||||
Output is similar to:
|
||||
|
||||
#Updated following nodes:
|
||||
type name id type-model serial-number address
|
||||
fsp Server-9125-F2A-SN0262672-new 3 9125-F2A 0262672 192.168.200.243
|
||||
|
||||
=head1 FILES
|
||||
|
||||
/opt/xcat/bin/rscan
|
||||
|
Loading…
Reference in New Issue
Block a user