diff --git a/perl-xCAT/xCAT/PPCcfg.pm b/perl-xCAT/xCAT/PPCcfg.pm index 8a4dda9b4..bcb41d206 100644 --- a/perl-xCAT/xCAT/PPCcfg.pm +++ b/perl-xCAT/xCAT/PPCcfg.pm @@ -12,7 +12,7 @@ use xCAT::Usage; ########################################## my %rspconfig = ( sshcfg => \&sshcfg, - frame => \&frame + frame => \&frame ); @@ -144,7 +144,7 @@ sub parse_args { # Return method to invoke #################################### if ( exists($cmds{frame}) ) { - $request->{hcp} = "hmc"; + $request->{hwcp} = "hmc"; $request->{method} = "cfg"; return( \%opt ); } @@ -259,7 +259,6 @@ sub cfg { return( $result ); } - ########################################################################## # Enables/disables/displays SSH access to HMC/IVM ########################################################################## diff --git a/perl-xCAT/xCAT/PPCcli.pm b/perl-xCAT/xCAT/PPCcli.pm index 3e5132038..f38472d70 100644 --- a/perl-xCAT/xCAT/PPCcli.pm +++ b/perl-xCAT/xCAT/PPCcli.pm @@ -92,9 +92,20 @@ my %rmsysconn = ( # lssysconn support formats ############################################## my %lssysconn = ( - all => "lssysconn -r all" + all => "lssysconn -r all", + alls => "lssysconn -r all -F %s" ); +############################################## +# Change IP address for managed systems +# or frames +############################################## +my %chsyspwd = ( + fsp => "chsyspwd -t %s -m %s --passwd %s --newpasswd %s", + bpa => "chsyspwd -t %s -e %s --passwd %s --newpasswd %s" +); + + ########################################################################## # Logon to remote server ########################################################################## @@ -1205,8 +1216,10 @@ sub network_reset { ########################################################################## sub lssysconn { - my $exp = shift; - my $cmd = $lssysconn{all}; + my $exp = shift; + my $res = shift; + my $filter = shift; + my $cmd = sprintf( $lssysconn{$res}, $filter ); my $result = send_cmd( $exp, $cmd); return ( $result); } @@ -1226,6 +1239,23 @@ sub mksysconn return ( $result); } +########################################################################## +# Change IP address for managed systems or frames +########################################################################## +sub chsyspwd +{ + my $exp = shift; + my $user = shift; + my $type = shift; + my $mtms = shift; + my $passwd = shift; + my $newpwd = shift; + + my $cmd = sprintf( $chsyspwd{$type}, $user, $mtms, $passwd, $newpwd ); + my $result = send_cmd( $exp, $cmd); + return ( $result ); +} + ########################################################################## # Remove connection for CEC/BPA ########################################################################## diff --git a/perl-xCAT/xCAT/PPCconn.pm b/perl-xCAT/xCAT/PPCconn.pm index f0bd548f5..bffb68c21 100644 --- a/perl-xCAT/xCAT/PPCconn.pm +++ b/perl-xCAT/xCAT/PPCconn.pm @@ -54,7 +54,7 @@ sub mkhwconn_parse_args $Getopt::Long::ignorecase = 0; Getopt::Long::Configure( "bundling" ); - if ( !GetOptions( \%opt, qw(V|verbose h|help t p=s P=s) )) { + if ( !GetOptions( \%opt, qw(V|verbose h|help t p=s P=s N=s) )) { return( usage() ); } return usage() if ( exists $opt{h}); @@ -277,9 +277,9 @@ sub rmhwconn_parse_args my $usage_string = xCAT::Usage->getUsage("rmhwconn"); return( [ $_[0], $usage_string] ); }; -############################################# -# Get options in command line -############################################# + ############################################# + # Get options in command line + ############################################# local @ARGV = ref($args) eq 'ARRAY'? @$args:(); $Getopt::Long::ignorecase = 0; Getopt::Long::Configure( "bundling" ); @@ -399,16 +399,10 @@ sub mkhwconn } if (!$node_ip) { - my $ip_tmp_res = xCAT::Utils::toIP($node_name); - ($Rc, $node_ip) = @$ip_tmp_res; - if ( $Rc ) - { - push @value, [$node_name, $node_ip, $Rc]; - next; - } + push @value, [$node_name, $node_ip, $Rc]; + next; } - - my ( undef,undef,undef,undef,$type) = @$d; + my ( undef,undef,$mtms,undef,$type) = @$d; my ($user, $passwd); if ( exists $opt->{P}) { @@ -432,6 +426,14 @@ sub mkhwconn { sethmcmgt( $node_name, $exp->[3]); } + +# if ( exists $opt->{N} ) +# { +# my $newpwd = $opt->{N}; +# my $Res = xCAT::PPCcli::chsyspwd( $exp, "access", $type, $mtms, $passwd, $newpwd ); +# $Rc = shift @$Res; +# push @value, [$node_name, @$Res[0], $Rc]; +# } } } return \@value; @@ -449,8 +451,9 @@ sub lshwconn my @value = (); my $Rc = undef; + my $hosttab = xCAT::Table->new( 'hosts' ); - my $res = xCAT::PPCcli::lssysconn( $exp); + my $res = xCAT::PPCcli::lssysconn( $exp, "all" ); $Rc = shift @$res; if ( $request->{nodetype} eq 'hmc') { @@ -526,13 +529,8 @@ sub lshwconn } if (!$node_ip) { - my $ip_tmp_res = xCAT::Utils::toIP($node_name); - ($Rc, $node_ip) = @$ip_tmp_res; - if ( $Rc ) - { - push @value, [$node_name, $node_ip, $Rc]; - next; - } + push @value, [$node_name, $node_ip, $Rc]; + next; } if ( my @res_matched = grep /\Qipaddr=$node_ip,\E/, @$res) @@ -590,13 +588,8 @@ sub rmhwconn } if (!$node_ip) { - my $ip_tmp_res = xCAT::Utils::toIP($node_name); - ($Rc, $node_ip) = @$ip_tmp_res; - if ( $Rc ) - { - push @value, [$node_name, $node_ip, $Rc]; - next; - } + push @value, [$node_name, $node_ip, $Rc]; + next; } my $res = xCAT::PPCcli::rmsysconn( $exp, $type, $node_ip); diff --git a/perl-xCAT/xCAT/PPCdb.pm b/perl-xCAT/xCAT/PPCdb.pm index e6edd451e..46f8d360c 100644 --- a/perl-xCAT/xCAT/PPCdb.pm +++ b/perl-xCAT/xCAT/PPCdb.pm @@ -73,6 +73,7 @@ sub add_ppc { $id, $model, $serial, + $side, $server, $pprofile, $parent, @@ -149,10 +150,12 @@ sub add_ppc { if ( $type =~ /^(fsp|bpa)$/ ) { $db{vpd}->setNodeAttribs( $name, { mtm=>$model, - serial=>$serial + serial=>$serial, + side=>$side }); $db{vpd}{commit} = 1; } + } ################################### @@ -174,7 +177,7 @@ sub update_ppc { my $hwtype = shift; my $values = shift; my $not_overwrite = shift; - my @tabs = qw(ppc vpd nodehm nodelist nodetype ppcdirect); + my @tabs = qw(ppc vpd nodehm nodelist nodetype ppcdirect hosts); my %db = (); my %nodetype = ( fsp => $::NODETYPE_FSP, @@ -194,7 +197,8 @@ sub update_ppc { return( "Error opening '$_'" ); } } - my @vpdlist = $db{vpd}->getAllNodeAttribs(['node','serial','mtm']); + my @vpdlist = $db{vpd}->getAllNodeAttribs(['node','serial','mtm','side']); + my @hostslist = $db{hosts}->getAllNodeAttribs(['node','ip']); my @ppclist = $db{ppc}->getAllNodeAttribs(['node','hcp','id', 'pprofile','parent','supernode', 'comments', 'disable']); @@ -207,6 +211,7 @@ sub update_ppc { $id, $model, $serial, + $side, $server, $pprofile, $parent, @@ -217,7 +222,7 @@ sub update_ppc { my $predefined_node = undef; foreach my $vpdent (@vpdlist) { - if ( $vpdent->{mtm} eq $model && $vpdent->{serial} eq $serial) + if ( $vpdent->{mtm} eq $model && $vpdent->{serial} eq $serial && $vpdent->{side} eq $side ) { $predefined_node = $vpdent->{node}; last; @@ -226,7 +231,13 @@ sub update_ppc { next if ( !$predefined_node); - if ( update_node_attribs($hwtype, $type, $name, $id, $model, $serial, + if ( $predefined_node =~ /-A$/ ) { + $name = $name . "-A"; + } elsif ( $predefined_node =~ /-B$/ ) { + $name = $name . "-B"; + } + + if ( update_node_attribs($hwtype, $type, $name, $id, $model, $serial, $side, $server, $pprofile, $parent, $ips, \%db, $predefined_node, \@ppclist)) { @@ -243,6 +254,7 @@ sub update_ppc { $id, $model, $serial, + $side, $server, $pprofile, $parent, @@ -253,7 +265,7 @@ sub update_ppc { my $predefined_node = undef; foreach my $vpdent (@vpdlist) { - if ( $vpdent->{mtm} eq $model && $vpdent->{serial} eq $serial) + if ( $vpdent->{mtm} eq $model && $vpdent->{serial} eq $serial && $vpdent->{side} eq $side ) { $predefined_node = $vpdent->{node}; last; @@ -262,7 +274,12 @@ sub update_ppc { next if ( !$predefined_node); - if (update_node_attribs($hwtype, $type, $name, $id, $model, $serial, + if ( $predefined_node =~ /-A$/ ) { + $name = $name . "-A"; + } elsif ( $predefined_node =~ /-B$/ ) { + $name = $name . "-B"; + } + if (update_node_attribs($hwtype, $type, $name, $id, $model, $serial, $side, $server, $pprofile, $parent, $ips, \%db, $predefined_node, \@ppclist)) { @@ -292,6 +309,7 @@ sub update_node_attribs my $id = shift; my $model = shift; my $serial = shift; + my $side = shift; my $server = shift; my $pprofile = shift; my $parent = shift; @@ -311,7 +329,7 @@ sub update_node_attribs 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}->setNodeAttribs( $name, { mtm=>$model, serial=>$serial, side=>$side}); $db->{vpd}->{commit} = 1; $updated = 1; } @@ -408,6 +426,18 @@ sub update_node_attribs $db->{nodelist}->{commit} = 1; $updated = 1; } + + ########################### + # Update hosts table + ########################### + my $hostslisthash = $db->{hosts}->getNodeAttribs( $name, [qw(ip)]); + if ( $namediff ) + { + $db->{hosts}->delEntries( $key_col); + $db->{hosts}->setNodeAttribs( $name,{ip=>$ips} ); + $db->{hosts}->{commit} = 1; + $updated = 1; + } return $updated; } @@ -581,7 +611,7 @@ sub credentials { if ( !$user_specified or $user eq @{$logon{$hwtype}}[0]) { $user = @{$logon{$hwtype}}[0]; - $pass = @{$logon{$hwtype}}[1]; + $pass = @{$logon{$hwtype}}[1]; } ########################################### @@ -643,6 +673,5 @@ sub credentials { return( $user,$pass ); } - 1; diff --git a/perl-xCAT/xCAT/PPCscan.pm b/perl-xCAT/xCAT/PPCscan.pm index 55e6bf50f..6b5d5aa80 100644 --- a/perl-xCAT/xCAT/PPCscan.pm +++ b/perl-xCAT/xCAT/PPCscan.pm @@ -21,9 +21,10 @@ my @header = ( ["id", "%-8s" ], ["type-model", "%-12s" ], ["serial-number", "%-15s" ], + ["side", "%-6s" ], ["address", "%s\n" ]); -my @attribs = qw(nodetype node id mtm serial hcp pprofile parent groups mgt cons); +my @attribs = qw(nodetype node id mtm serial side hcp pprofile parent groups mgt cons); my %nodetype = ( fsp => $::NODETYPE_FSP, bpa => $::NODETYPE_BPA, @@ -133,6 +134,7 @@ sub enumerate { my $server = @$exp[3]; my @values = (); my %cage = (); + my %hwconn = (); my $Rc; my $filter; @@ -157,9 +159,37 @@ sub enumerate { my $prof = ""; my $ips = ""; my $bpa = ""; + my $side = ""; push @values, join( ",", - $hwtype,$server,$id,$model,$serial,$server,$prof,$bpa,$ips ); + $hwtype,$server,$id,$model,$serial,$side,$server,$prof,$bpa,$ips ); + } + + ######################################### + # Save hardware connections + ######################################### + $filter = "type_model_serial_num,ipaddr,sp,side"; + my $conns = xCAT::PPCcli::lssysconn( $exp, "alls", $filter ); + $Rc = shift(@$conns); + + ######################################### + # Return error + ######################################### + if ( $Rc != SUCCESS ) { + return( @$conns[0] ); + } + + foreach my $con ( @$conns ) { + my ($mtms,$ipaddr,$sp,$side) = split /,/,$con; + my $value = undef; + + if ( $sp =~ /^primary$/ or $side =~ /^a$/ ) { + $value = "A"; + } elsif ($sp =~ /^secondary$/ or $side =~ /^b$/ ) { + $value = "B"; + } + + $hwconn{$ipaddr} = "$mtms,$value"; } ######################################### @@ -258,11 +288,21 @@ sub enumerate { if ( defined($host) ) { $fname = $host; } - my $bpastr = join( ",","bpa",$fname,$id,$model,$serial,$server,$prof,$bpa,"$ipa $ipb"); + + ####################################### + # Save two sides of BPA seperately + ####################################### + my $bpastr = join( ",","bpa",$fname,$id,$model,$serial,"A",$server,$prof,$bpa,$ipa); if ( !grep /^\Q$bpastr\E$/, @values) { push @values, join( ",", - "bpa",$fname,$id,$model,$serial,$server,$prof,$bpa,"$ipa $ipb"); + "bpa",$fname,$id,$model,$serial,"A",$server,$prof,$bpa,$ipa); + } + $bpastr = join( ",","bpa",$fname,$id,$model,$serial,"B",$server,$prof,$bpa,$ipb); + if ( !grep /^\Q$bpastr\E$/, @values) + { + push @values, join( ",", + "bpa",$fname,$id,$model,$serial,"B",$server,$prof,$bpa,$ipb); } } ##################################### @@ -278,8 +318,11 @@ sub enumerate { if ( defined($host) ) { $fsp = $host; } + + my $mtmss = $hwconn{$ips}; + my ($mtms,$side) = split /,/, $mtmss; push @values, join( ",", - "fsp",$fsp,$cageid,$model,$serial,$server,$prof,$fname,$ips ); + "fsp",$fsp,$cageid,$model,$serial,$side,$server,$prof,$fname,$ips ); ##################################### # Enumerate LPARs @@ -312,12 +355,13 @@ sub enumerate { my ($name,$lparid,$dprof,$curprof) = split /,/; my $prof = (length($curprof) && ($curprof !~ /^none$/)) ? $curprof : $dprof; my $ips = ""; + my $port = ""; ##################################### # Save LPAR information ##################################### push @values, join( ",", - "lpar",$name,$lparid,$model,$serial,$server,$prof,$fsp,$ips ); + "lpar",$name,$lparid,$model,$serial,$port,$server,$prof,$fsp,$ips ); } } return( \@values ); diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index ba594c514..5154d6965 100644 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -701,13 +701,14 @@ switch => { }, }, vpd => { - cols => [qw(node serial mtm asset comments disable)], + cols => [qw(node serial mtm side asset comments disable)], keys => [qw(node)], table_desc => 'The Machine type, Model, and Serial numbers of each node.', descriptions => { node => 'The node name or group name.', serial => 'The serial number of the node.', mtm => 'The machine type and model number of the node. E.g. 7984-6BU', + side => 'The side information for the BPA/FSP', asset => 'A field for administators to use to correlate inventory numbers they may have to accomodate', comments => 'Any user-written notes.', disable => "Set to 'yes' or '1' to comment out this row.", @@ -1130,6 +1131,10 @@ my @nodeattrs = ( {attr_name => 'mtm', tabentry => 'vpd.mtm', access_tabentry => 'vpd.node=attr:node', + }, + {attr_name => 'side', + tabentry => 'vpd.side', + access_tabentry => 'vpd.node=attr:node', }, ################## # mac table # diff --git a/xCAT-server/lib/perl/xCAT/PPC.pm b/xCAT-server/lib/perl/xCAT/PPC.pm index 0585f5c5f..fd4760c35 100644 --- a/xCAT-server/lib/perl/xCAT/PPC.pm +++ b/xCAT-server/lib/perl/xCAT/PPC.pm @@ -678,7 +678,7 @@ sub preprocess_nodes { # rscan - Nodes are hardware control pts # FSPpower, FSPinv and FSPrflash ######################################## - if (( !$request->{hcp} && ($request->{hcp} ne "hmc" )) + if (( !$request->{hwcp} && ($request->{hwcp} ne "hmc" )) and ($request->{command} !~ /^renergy$/) and (( $request->{command} =~ /^(rscan|rspconfig)$/ ) or ($request->{hwtype} eq "fsp" or $request->{hwtype} eq "bpa" ) @@ -749,7 +749,7 @@ sub preprocess_nodes { ########################################## while (my ($hcp,$hash) = each(%nodehash) ) { my @cred; - if ($request->{hcp} && ($request->{hcp} eq "hmc" )) { + if ($request->{hwcp} && ($request->{hwcp} eq "hmc" )) { @cred = xCAT::PPCdb::credentials( $hcp, $request->{hcp} ); } else { @cred = xCAT::PPCdb::credentials( $hcp, $request->{hwtype} ); @@ -1111,7 +1111,7 @@ sub invoke_cmd { my $hwtype = $request->{hwtype}; my $verbose = $request->{verbose}; my $cmd = $request->{command}; - my $power = $request->{hcp}; + my $power = $request->{hwcp}; my @exp; my $verbose_log; my @outhash; diff --git a/xCAT-server/lib/xcat/plugins/lsslp.pm b/xCAT-server/lib/xcat/plugins/lsslp.pm index 3ef1d537c..8166ac686 100644 --- a/xCAT-server/lib/xcat/plugins/lsslp.pm +++ b/xCAT-server/lib/xcat/plugins/lsslp.pm @@ -38,7 +38,7 @@ use constant { TYPE_HMC => "HMC", TYPE_IVM => "IVM", TYPE_FSP => "FSP", - IP_ADDRESSES => 3, + IP_ADDRESSES => 4, TEXT => 0, FORMAT => 1, SUCCESS => 0, @@ -65,6 +65,7 @@ my @header = ( ["device", "%-8s" ], ["type-model", "%-12s"], ["serial-number", "%-15s"], + ["side", "%-6s" ], ["ip-addresses", "placeholder"], ["hostname", "%s"] ); @@ -95,7 +96,7 @@ my %mgt = ( lc(TYPE_RSA) => "blade" ); -my @attribs = qw(nodetype model serial groups node mgt mpa id); +my @attribs = qw(nodetype model serial groups node mgt mpa id side); my $verbose = 0; my %ip_addr = (); my %slp_result = (); @@ -1110,8 +1111,13 @@ sub gethost_from_url { my $type = shift; my $mtm = shift; my $sn = shift; + my $side = shift; my $iplist = shift; + if ( $side =~ /^N\/A$/ ) { + $side = undef; + } + ####################################### # Extract IP from URL ####################################### @@ -1137,33 +1143,17 @@ sub gethost_from_url { if ( !%::VPD_TAB_CACHE) { my $vpdtab = xCAT::Table->new( 'vpd' ); - my @entries = $vpdtab->getAllNodeAttribs(['node','mtm','serial']); + my @entries = $vpdtab->getAllNodeAttribs(['node','mtm','serial','side']); #Assuming IP is unique in hosts table for my $entry ( @entries) { - if ( $entry->{mtm} and $entry->{serial}) + if ( $entry->{mtm} and $entry->{serial} and defined( $entry->{side} )) { - $::VPD_TAB_CACHE{$entry->{ 'node'}} = $entry->{mtm} . '*' . $entry->{serial}; + $::VPD_TAB_CACHE{$entry->{ 'node'}} = $entry->{mtm} . '*' . $entry->{serial} . '-' . $entry->{side}; } } } - ############################################################### - # Convert IP to hostname (Accoording to DNS or /etc/hosts - ############################################################### - my $host = gethostbyaddr( $packed, AF_INET ); - if ( !$host or $! ) { - #Tentative solution - return undef if ($opt{H}); - } - - if ( $host ) { - if ( $::VPD_TAB_CACHE{$host} ) { - delete $::VPD_TAB_CACHE{$host}; - } - return( "$host($ip)" ); - } - if ( $rsp =~ /\(machinetype-model=(.*?)\)/ ) { my $mtm = $1; @@ -1171,18 +1161,13 @@ sub gethost_from_url { { my $sn = $1; foreach my $node ( keys %::VPD_TAB_CACHE ) { - if ( $::VPD_TAB_CACHE{$node} eq $mtm . '*' . $sn ) { - my $iip = gethostbyname($node); - if ( !$iip ) { - - delete $::VPD_TAB_CACHE{$node}; - return $node . "($ip)"; - } + if ( $::VPD_TAB_CACHE{$node} eq $mtm . '*' . $sn . '-' . $side ) { + delete $::VPD_TAB_CACHE{$node}; + return $node . "($ip)"; } } } } - ####################################### # Read host from hosts table ####################################### @@ -1199,12 +1184,12 @@ sub gethost_from_url { } } } - if ( exists $::HOST_TAB_CACHE{ $ip}) + if ( exists $::HOST_TAB_CACHE{$ip}) { - return $::HOST_TAB_CACHE{ $ip} ."($ip)"; + return $::HOST_TAB_CACHE{$ip} . "($ip)"; } - $host = getFactoryHostname($type,$mtm,$sn,$rsp); + my $host = getFactoryHostname($type,$mtm,$sn,$side,$rsp); ####################################### # Convert hostname to short-hostname ####################################### @@ -1231,6 +1216,7 @@ sub getFactoryHostname my $type = shift; my $mtm = shift; my $sn = shift; + my $side = shift; my $rsp = shift; my $host = undef; @@ -1247,7 +1233,7 @@ sub getFactoryHostname if ( $type eq SERVICE_FSP or $type eq SERVICE_BPA) { - $host = "Server-$mtm-SN$sn"; + $host = "Server-$mtm-SN$sn-$side"; } return $host; } @@ -1366,6 +1352,7 @@ sub parse_responses { "type", "machinetype-model", "serial-number", + "slot", "ip-address" ); ####################################### @@ -1375,6 +1362,7 @@ sub parse_responses { "type", "enclosure-machinetype-model", "enclosure-serial-number", + "slot", "ip-address" ); foreach my $rsp ( @$values ) { @@ -1424,9 +1412,17 @@ sub parse_responses { if ( $verbose ) { trace( $request, "Attribute not found: [$_]->($rsp)" ); } - next; + push @result, "N/A"; + next; } - push @result, $1; + my $val = $1; + if (( $_ =~ /^slot$/ ) and ( $val == 0 )) { + push @result, "B"; + } elsif (( $_ =~ /^slot$/ ) and ( $val == 1 )) { + push @result, "A"; + } else { + push @result, $val; + } } ########################################### @@ -1503,7 +1499,6 @@ sub parse_responses { # Also, remove those nodes that have same IP addresses and # give a warning message. ########################################################## - my %hostname_record; my %ip_record; for my $h ( keys %outhash) { @@ -1512,21 +1507,13 @@ sub parse_responses { { $name = $1; $ip = $2; + } else { next; } -# my $name_node_pair = {$name=>$h}; -# if ( not exists $ip_record{$ip}) -# { -# $ip_record{$ip} = [$name_node_pair]; -# } -# else -# { -# push @{$ip_record{$ip}}, $name_node_pair; -# } if ( ! $ip_record{$ip}) { $ip_record{$ip} = $h; @@ -1538,25 +1525,6 @@ sub parse_responses { xCAT::MsgUtils->message("W", $response, $request->{callback}); delete $outhash{$h}; } - - if (exists $hostname_record{$name}) - { - #Name is duplicated - my ($old_h, $old_ip) = @{$hostname_record{$name}}; - #if the node has been defined, keep one for old node name - #otherwise create new node name - $outhash{$old_h}->[4] = $name . "-1" . "($old_ip)"; - $outhash{$name . "-1" . "($old_ip)"} = $outhash{$old_h}; - delete $outhash{$old_h}; - - $outhash{$h}->[4] = $name . "-2" . "($ip)"; - $outhash{$name . "-2" . "($ip)"} = $outhash{$h}; - delete $outhash{$h}; - } - else - { - $hostname_record{$name} = [$h,$ip]; - } } return( \%outhash ); @@ -1579,17 +1547,15 @@ sub xCATdB { $vpdtab = xCAT::Table->new('vpd'); if ($vpdtab) { - my @ents=$vpdtab->getAllNodeAttribs(['serial','mtm']); + my @ents=$vpdtab->getAllNodeAttribs(['serial','mtm','side']); for my $ent ( @ents) { - if ( $ent->{mtm} and $ent->{serial}) + if ( $ent->{mtm} and $ent->{serial} and defined( $ent->{side} )) { # if there is no BPA, or there is the second BPA, change it - if ( ! exists $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} or - $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} =~ /-2$/ - ) + if ( ! exists $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial} . "-" . $ent->{side}} ) { - $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial}} = $ent->{node}; + $sn_node{"Server-" . $ent->{mtm} . "-SN" . $ent->{serial} . "-" . $ent->{side}} = $ent->{node}; } } } @@ -1598,7 +1564,7 @@ sub xCATdB { foreach ( keys %$outhash ) { my $data = $outhash->{$_}; my $type = @$data[0]; - my $nameips = @$data[4]; + my $nameips = @$data[5]; my ($name,$ips); if ( $nameips =~ /^([^\(]+)\(([^\)]+)\)$/) { @@ -1607,17 +1573,19 @@ sub xCATdB { $host_ip{$name} = $ips; } - $ips = @$data[3] if ( !$ips); - $name = @$data[4] if ( !$name); + $ips = @$data[4] if ( !$ips); + $name = @$data[5] if ( !$name); - my $hostip = xCAT::Utils::updateEtcHosts($name,$ips); - $name = @$hostip[0]; - $ips = @$hostip[1]; + ######################################## + # Write result to hosts table + ######################################## + my $hostip = writehost($name,$ips); if ( $type =~ /^BPA$/ ) { my $model = @$data[1]; my $serial = @$data[2]; - my $id = @$data[6]; + my $side = @$data[3]; + my $id = @$data[7]; #################################### # N/A Values @@ -1626,7 +1594,7 @@ sub xCATdB { my $frame = ""; my $values = join( ",", - lc($type),$name,$id,$model,$serial,$name,$prof,$frame,$ips ); + lc($type),$name,$id,$model,$serial,$side,$name,$prof,$frame,$ips ); xCAT::PPCdb::add_ppc( lc($type), [$values],1 ); } elsif ( $type =~ /^(HMC|IVM)$/ ) { @@ -1639,11 +1607,12 @@ sub xCATdB { my $frame = ""; my $model = @$data[1]; my $serial = @$data[2]; - $ips = @$data[3] if ( !$ips); - $name = @$data[4] if ( !$name); - my $bpc_model = @$data[6]; - my $bpc_serial = @$data[7]; - my $cageid = @$data[8]; + my $side = @$data[3]; + $ips = @$data[4] if ( !$ips); + $name = @$data[5] if ( !$name); + my $bpc_model = @$data[7]; + my $bpc_serial = @$data[8]; + my $cageid = @$data[9]; ############################################################ # For HE machine, there are 2 FSPs, but only one FSP have the @@ -1656,13 +1625,13 @@ sub xCATdB { { if ( $model eq $outhash->{$he_node}->[1] and $serial eq $outhash->{$he_node}->[2] and - $outhash->{$he_node}->[6] and - $outhash->{$he_node}->[7] + $outhash->{$he_node}->[8] and + $outhash->{$he_node}->[9] ) { - $bpc_model = $outhash->{$he_node}->[6]; - $bpc_serial = $outhash->{$he_node}->[7]; - $cageid = $outhash->{$he_node}->[8]; + $bpc_model = $outhash->{$he_node}->[7]; + $bpc_serial = $outhash->{$he_node}->[8]; + $cageid = $outhash->{$he_node}->[9]; } } } @@ -1699,7 +1668,7 @@ sub xCATdB { # the short-hostname as the name. ######################################## if ( $name =~ /^[\d]{1}/ ) { - $name = "Server-$model-$serial"; + $name = "Server-$model-$serial-$side"; } ######################################## # N/A Values @@ -1708,7 +1677,7 @@ sub xCATdB { my $server = ""; my $values = join( ",", - lc($type),$name,$cageid,$model,$serial,$name,$prof,$frame,$ips ); + lc($type),$name,$cageid,$model,$serial,$side,$name,$prof,$frame,$ips ); xCAT::PPCdb::add_ppc( "fsp", [$values],1 ); } elsif ( $type =~ /^(RSA|MM)$/ ) { @@ -1733,7 +1702,9 @@ sub format_stanza { foreach ( keys %$outhash ) { my @data = @{$outhash->{$_}}; my $type = lc($data[0]); - my $name = $data[4]; + my $name = $data[5]; + my $ip = $data[4]; + my $side = $data[3]; my $i = 0; ################################# @@ -1761,7 +1732,16 @@ sub format_stanza { } else { next; } + } elsif ( /^side$/ ) { + if ( $type =~ /^(fsp|bpa)$/ ) { + $d = $side; + } else { + next; + } + } elsif ( /^ip$/ ) { + $d = $ip; } + $result .= "\t$_=$d\n"; } } @@ -1784,7 +1764,9 @@ sub format_xml { foreach ( keys %$outhash ) { my @data = @{ $outhash->{$_}}; my $type = lc($data[0]); - my $name = $data[4]; + my $name = $data[5]; + my $ip = $data[4]; + my $side = $data[3]; my $i = 0; ################################# @@ -1811,6 +1793,16 @@ sub format_xml { } else { next; } + } elsif ( /^side$/ ) { + if ( $type =~ /^(fsp|bpa)$/ ) { + $d = $side; + } else { + next; + } + } elsif ( /^node$/ ) { + $d = $name; + } elsif ( /^ip$/ ) { + $d = $ip; } $href->{Node}->{$_} = $d; } @@ -2841,6 +2833,24 @@ sub process_request { return( $Rc ); } +########################################################################## +# Write hostnames and IP address to host table. If an existing entry +# with same IP address can be found, return the existing hostname and IP +########################################################################## +sub writehost { + + my $hostname = shift; + my $ip = shift; + + my $hoststab = xCAT::Table->new( "hosts", -create=>1, -autocommit=>1 ); + if ( !$hoststab ) { + return( [[$hostname,"Error opening 'hosts' table",RC_ERROR]] ); + } + + $hoststab->setNodeAttribs( $hostname,{ip=>$ip} ); + $hoststab->close(); +} + 1;