From 572b0cfb96f670624310e07e9872e1ee93964556 Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Fri, 28 Aug 2015 22:08:17 +0000 Subject: [PATCH 1/4] [perl-xCAT] Fix tabs and indentation in DBobjUtils --- perl-xCAT/xCAT/DBobjUtils.pm | 372 +++++++++++++++++------------------ 1 file changed, 186 insertions(+), 186 deletions(-) diff --git a/perl-xCAT/xCAT/DBobjUtils.pm b/perl-xCAT/xCAT/DBobjUtils.pm index 19428d0e0..3499b2ce3 100755 --- a/perl-xCAT/xCAT/DBobjUtils.pm +++ b/perl-xCAT/xCAT/DBobjUtils.pm @@ -65,7 +65,7 @@ sub getObjectsOfType { # get the key for this type object - # ex. for "network" type the key is "netname" + # ex. for "network" type the key is "netname" # get the data type spec from Schema.pm my $datatype = $xCAT::Schema::defspec{$type}; @@ -116,7 +116,7 @@ sub getObjectsOfType } } } - + @{$::saveObjList{$type}} = @objlist; } @@ -143,7 +143,7 @@ sub getObjectsOfType %tabhash = xCAT::DBobjUtils->getobjattrs(\%typehash); Comments: - For now - only support tables that have 'node' as key !!! + For now - only support tables that have 'node' as key !!! =cut #----------------------------------------------------------------------------- @@ -172,10 +172,10 @@ sub getobjattrs # go through each object type and look up all the info for each object foreach my $objtype (keys %objtypelist) { - # only do node type for now + # only do node type for now if ($objtype eq 'node') { # find the list of tables and corresponding attrs - # - for this object type + # - for this object type # get the object type decription from Schema.pm my $datatype = $xCAT::Schema::defspec{$objtype}; foreach my $this_attr (@{$datatype->{'attrs'}}) { @@ -215,8 +215,8 @@ sub getobjattrs # fill in %tabhash with any values that are set foreach my $n (@objlist) { - my $tmp1=$rec->{$n}->[0]; - foreach $a (@{$tableattrs{$table}}) { + my $tmp1=$rec->{$n}->[0]; + foreach $a (@{$tableattrs{$table}}) { if (defined($tmp1->{$a})) { $tabhash{$table}{$n}{$a} = $tmp1->{$a}; #print "obj = $n, table = $table, attr =$a, val = $tabhash{$table}{$n}{$a}\n"; @@ -224,7 +224,7 @@ sub getobjattrs # Add a has been searched flag to improve the performance $tabhash{$table}{$n}{"$a"."_hassearched"} = 1; } - } + } } #$thistable->commit; } @@ -252,11 +252,11 @@ sub getobjattrs Error: Example: - To use create hash for objectname and object type - ex. $objhash{$obj} = $type; + To use create hash for objectname and object type + ex. $objhash{$obj} = $type; - - then call as follows: - %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash); + - then call as follows: + %myhash = xCAT::DBobjUtils->getobjdefs(\%objhash); Comments: @@ -359,13 +359,13 @@ sub getobjdefs { my $rsp; $rsp->{data}->[0] ="Could not read the \'$objname\' object from the \'site\' table."; - xCAT::MsgUtils->message("E", $rsp, $::callback); + xCAT::MsgUtils->message("E", $rsp, $::callback); } } } elsif ($objtype eq 'monitoring') { # need a special case for the monitoring table - # - need to check the monsetting table for entries that contain - # the same name as the monitoring table entry. + # - need to check the monsetting table for entries that contain + # the same name as the monitoring table entry. my @TableRowArray = xCAT::DBobjUtils->getDBtable('monsetting'); foreach my $objname (sort @{$type_obj{$objtype}}) { if (@TableRowArray) { @@ -394,7 +394,7 @@ sub getobjdefs { my $rsp; $rsp->{data}->[0] ="Could not read the \'$objname\' object from the \'monsetting\' table."; - xCAT::MsgUtils->message("E", $rsp, $::callback); + xCAT::MsgUtils->message("E", $rsp, $::callback); } } } elsif (($objtype eq 'auditlog') || ($objtype eq 'eventlog')) { @@ -472,7 +472,7 @@ sub getobjdefs # !!!! some tables depend on the value of certain attrs # we need to look up attrs in the correct order or we will # not be able to determine what tables to look - # in for some attrs. + # in for some attrs. if (exists($this_attr->{only_if})) { my ($check_attr, $check_value) = split('\=', $this_attr->{only_if}); @@ -605,7 +605,7 @@ sub getDBtable my ($class, $table) = @_; my @rows = []; - # save this table info - in case this subr gets called multiple times + # save this table info - in case this subr gets called multiple times # --nocache flag specifies not to use cahe if (grep(/^$table$/, @::foundTableList) && !$::opt_nc) { @@ -617,35 +617,35 @@ sub getDBtable else { - # need to get info from DB - my $thistable = xCAT::Table->new($table, -create => 1); - if (!$thistable) - { - return undef; - } + # need to get info from DB + my $thistable = xCAT::Table->new($table, -create => 1); + if (!$thistable) + { + return undef; + } - #@rows = $thistable->getTable; - @rows = @{$thistable->getAllEntries()}; + #@rows = $thistable->getTable; + @rows = @{$thistable->getAllEntries()}; - # !!!! this routine returns rows even if the table is empty!!!!!! + # !!!! this routine returns rows even if the table is empty!!!!!! - # keep track of the fact that we checked this table + # keep track of the fact that we checked this table # - even if it's empty! push(@::foundTableList, $thistable->{tabname}); @{$::TableHash{$table}} = @rows; - #$thistable->commit; + #$thistable->commit; - } # end if not cached + } # end if not cached - if (@rows) - { - return @rows; - } - else - { - return undef; + if (@rows) + { + return @rows; + } + else + { + return undef; } } @@ -665,11 +665,11 @@ sub getDBtable Example: To use: - -create hash for objectname and object type - ex. $objhash{$object}{$attribute} = value; + -create hash for objectname and object type + ex. $objhash{$object}{$attribute} = value; - -then call as follows: - if (xCAT::DBobjUtils->setobjdefs(\%objhash) != 0) + -then call as follows: + if (xCAT::DBobjUtils->setobjdefs(\%objhash) != 0) Comments: @@ -704,9 +704,9 @@ sub setobjdefs %DBattrvals = xCAT::DBobjUtils->getobjdefs(\%DBhash, 0, \@attrs); # for each object figure out: - # - what tables to update - # - which table attrs correspond to which object attrs - # - what the keys are for each table + # - what tables to update + # - which table attrs correspond to which object attrs + # - what the keys are for each table # update the tables a row at a time foreach my $objname (keys %objhash) { @@ -714,7 +714,7 @@ sub setobjdefs # get attr=val that are set in the DB ?? my $type = $objhash{$objname}{objtype}; - # handle the monitoring table as a special case !!!!! + # handle the monitoring table as a special case !!!!! if ($type eq 'monitoring') { @@ -727,7 +727,7 @@ sub setobjdefs my @attrlist; foreach my $entry (@{$datatype->{'attrs'}}) { - push(@attrlist, $entry->{'attr_name'}); + push(@attrlist, $entry->{'attr_name'}); } # open the tables (monitoring and monsetting) @@ -918,9 +918,9 @@ sub setobjdefs { my $rsp; $rsp->{data}->[0] = - "Could not set the \'$attr\' attribute of the \'$objname\' object in the xCAT database."; + "Could not set the \'$attr\' attribute of the \'$objname\' object in the xCAT database."; $rsp->{data}->[1] = - "Error returned is \'$str->errstr\'."; + "Error returned is \'$str->errstr\'."; xCAT::MsgUtils->message("I", $rsp, $::callback); } $ret = 1; @@ -943,7 +943,7 @@ sub setobjdefs # get the object type decription from Schema.pm my $datatype = $xCAT::Schema::defspec{$type}; - # get the object key to look for, for this object type + # get the object key to look for, for this object type my $objkey = $datatype->{'objkey'}; # get a list of valid attr names @@ -1034,7 +1034,7 @@ sub setobjdefs # need to check the attrs we are setting for the object # as well as the attrs for this object that may be - # already set in DB + # already set in DB if ( !($objhash{$objname}{$check_attr}) && !($DBattrvals{$objname}{$check_attr}) ) { # if I didn't already check for this attr @@ -1143,7 +1143,7 @@ sub setobjdefs { # remove the specified list of values from the current - # attr values. + # attr values. if ($DBattrvals{$objname}{$attr_name}) { @@ -1159,12 +1159,12 @@ sub setobjdefs if (($::opt_t eq 'group') && ($DBattrvals{$objname}{'grouptype'} ne 'dynamic')) { my $rsp; - $rsp->{data}->[0] = "$objname is not a member of \'$em\'."; - xCAT::MsgUtils->message("W", $rsp, $::callback); + $rsp->{data}->[0] = "$objname is not a member of \'$em\'."; + xCAT::MsgUtils->message("W", $rsp, $::callback); } else { my $rsp; - $rsp->{data}->[0] = "$em is not in the attribute of \'$attr_name\' for the \'$objname\' definition."; - xCAT::MsgUtils->message("W", $rsp, $::callback); + $rsp->{data}->[0] = "$em is not in the attribute of \'$attr_name\' for the \'$objname\' definition."; + xCAT::MsgUtils->message("W", $rsp, $::callback); } } } @@ -1217,30 +1217,30 @@ my $tt = $invalidattr->{$att}->{valid}; } -# TODO - need to get back to this -if (0) { - # - # check to see if all the attrs got set - # + # TODO - need to get back to this + if (0) { + # + # check to see if all the attrs got set + # - my @errlist; - foreach $a (@attrprovided) - { - # is this attr was not set then add it to the error list - if (!grep(/^$a$/, @setattrlist)) - { - push(@errlist, $a); - $ret = 2; - } + my @errlist; + foreach $a (@attrprovided) + { + # is this attr was not set then add it to the error list + if (!grep(/^$a$/, @setattrlist)) + { + push(@errlist, $a); + $ret = 2; + } - } - if ($ret == 2) { - my $rsp; - $rsp->{data}->[0] = "Could not set the following attributes for the \'$objname\' definition in the xCAT database: \'@errlist\'"; - xCAT::MsgUtils->message("E", $rsp, $::callback); - } + } + if ($ret == 2) { + my $rsp; + $rsp->{data}->[0] = "Could not set the following attributes for the \'$objname\' definition in the xCAT database: \'@errlist\'"; + xCAT::MsgUtils->message("E", $rsp, $::callback); + } -} + } } # end - foreach object #==========================================================# @@ -1284,22 +1284,22 @@ if (0) { # 'tabattrs' => HASH(0x127842f4) # 'comments' => 'ddee' #=================================================================# - # now set the attribute values in the tables - # - handles all except site, monitoring & monsetting for now - if ($setattrs) { - foreach my $table (keys %allupdates) { + # now set the attribute values in the tables + # - handles all except site, monitoring & monsetting for now + if ($setattrs) { + foreach my $table (keys %allupdates) { - # get the keys for this table + # get the keys for this table my $schema = xCAT::Table->getTableSchema($table); my $keys = $schema->{keys}; # open the table my $thistable = xCAT::Table->new($table, -create => 1, -autocommit => 0); if (!$thistable) { - my $rsp; - $rsp->{data}->[0] = "Could not set the \'$thistable\' table."; - xCAT::MsgUtils->message("E", $rsp, $::callback); - return 1; + my $rsp; + $rsp->{data}->[0] = "Could not set the \'$thistable\' table."; + xCAT::MsgUtils->message("E", $rsp, $::callback); + return 1; } # Special case for the postscripts table @@ -1450,10 +1450,10 @@ if (0) { Error: Example: - To use create hash for object name and object type - ex. $objhash{$obj} = $type; - - then call as follows: - xCAT::DBobjUtils->rmobjdefs(\%objhash); + To use create hash for object name and object type + ex. $objhash{$obj} = $type; + - then call as follows: + xCAT::DBobjUtils->rmobjdefs(\%objhash); Comments: @@ -1630,7 +1630,7 @@ sub rmobjdefs =head3 readFileInput Process the command line input piped in from a file. - (Support stanza or xml format.) + (Support stanza or xml format.) Arguments: Returns: @@ -1641,8 +1641,8 @@ sub rmobjdefs Example: Comments: - Set @::fileobjtypes, @::fileobjnames, %::FILEATTRS - (i.e.- $::FILEATTRS{objname}{attr}=val) + Set @::fileobjtypes, @::fileobjnames, %::FILEATTRS + (i.e.- $::FILEATTRS{objname}{attr}=val) =cut @@ -1650,7 +1650,7 @@ sub rmobjdefs sub readFileInput { my ($class, $filedata) = @_; - my ($objectname, $junk1, $junk2); + my ($objectname, $junk1, $junk2); @::fileobjnames = (); @@ -1666,7 +1666,7 @@ sub readFileInput #} my $look_for_colon = 1; # start with first line that has a colon - my $objtype; + my $objtype; foreach my $l (@lines) { @@ -1748,10 +1748,10 @@ sub readFileInput $::FILEATTRS{$objectname}{$attr} = $val; # if the attr being set is "objtype" then check - # to see if we have any defaults set for this type + # to see if we have any defaults set for this type # the objtype should be the first etntry in each stanza - # so after we set the defaults they will be overwritten - # by any values that appear in the rest of the stanza + # so after we set the defaults they will be overwritten + # by any values that appear in the rest of the stanza if ($attr eq 'objtype') { push(@::fileobjtypes, $val); @@ -1793,15 +1793,15 @@ sub readFileInput Globals: Error: Example: - To use: + To use: - create hash for objectname and and attr values (need group - name (object), and grouptype & members attr values at a - minimum.) - - ex. $objhash{$obj}{$attr} = value; + name (object), and grouptype & members attr values at a + minimum.) + + ex. $objhash{$obj}{$attr} = value; - then call as follows: - xCAT::DBobjUtils->getGroupMembers($objectname, \%objhash); + xCAT::DBobjUtils->getGroupMembers($objectname, \%objhash); Comments: @@ -1834,7 +1834,7 @@ sub getGroupMembers { # if find the group name in the "groups" attr value then add the - # node name to the member list + # node name to the member list #if ($_->{'groups'} =~ /$objectname/) my @nodeGroupList = split(',', $_->{'groups'}); @@ -1856,7 +1856,7 @@ sub getGroupMembers { # find all nodes that satisfy the criteria specified in "wherevals" - # value + # value my %whereHash; my %tabhash; @@ -1879,7 +1879,7 @@ sub getGroupMembers my @tmplist = xCAT::DBobjUtils->getObjectsOfType('node'); # create a hash of obj names and types - my %tmphash; + my %tmphash; foreach my $n (@tmplist) { $tmphash{$n} = 'node'; @@ -1930,102 +1930,102 @@ sub getGroupMembers %nethash = xCAT::DBobjUtils->getNetwkInfo(\@targetnodes); - Comments: + Comments: =cut #----------------------------------------------------------------------------- sub getNetwkInfo { - my ($class, $ref_nodes) = @_; - my @nodelist = @$ref_nodes; + my ($class, $ref_nodes) = @_; + my @nodelist = @$ref_nodes; - my %nethash; - my @attrnames; + my %nethash; + my @attrnames; - # get the current list of network attrs (networks table columns) + # get the current list of network attrs (networks table columns) my $datatype = $xCAT::Schema::defspec{'network'}; - foreach my $a (@{$datatype->{'attrs'}}) { - my $attr = $a->{attr_name}; - push(@attrnames, $attr); - } + foreach my $a (@{$datatype->{'attrs'}}) { + my $attr = $a->{attr_name}; + push(@attrnames, $attr); + } - # read the networks table - my @TableRowArray = xCAT::DBobjUtils->getDBtable('networks'); - if (! @TableRowArray) + # read the networks table + my @TableRowArray = xCAT::DBobjUtils->getDBtable('networks'); + if (! @TableRowArray) { - return undef; - } + return undef; + } - # for each node - get the network info - foreach my $node (@nodelist) + # for each node - get the network info + foreach my $node (@nodelist) { - # get, check, split the node IP - my $IP = xCAT::NetworkUtils->getipaddr($node); - chomp $IP; - unless (($IP =~ /\d+\.\d+\.\d+\.\d+/) || ($IP =~ /:/)) - { - next; - } - my ($ia, $ib, $ic, $id) = split('\.', $IP); + # get, check, split the node IP + my $IP = xCAT::NetworkUtils->getipaddr($node); + chomp $IP; + unless (($IP =~ /\d+\.\d+\.\d+\.\d+/) || ($IP =~ /:/)) + { + next; + } + my ($ia, $ib, $ic, $id) = split('\.', $IP); - # check the entries of the networks table - # - if the bitwise AND of the IP and the netmask gives you - # the "net" name then that is the entry you want. - foreach (@TableRowArray) { - my $NM = $_->{'mask'}; - my $net=$_->{'net'}; - chomp $NM; - chomp $net; + # check the entries of the networks table + # - if the bitwise AND of the IP and the netmask gives you + # the "net" name then that is the entry you want. + foreach (@TableRowArray) { + my $NM = $_->{'mask'}; + my $net=$_->{'net'}; + chomp $NM; + chomp $net; - if(xCAT::NetworkUtils->ishostinsubnet($IP, $NM, $net)) - { - # fill in the hash - - foreach my $attr (@attrnames) { - if ( defined($_->{$attr}) ) { - $nethash{$node}{$attr} = $_->{$attr}; - } - } - if($nethash{$node}{'gateway'} eq '') - { - if(xCAT::NetworkUtils->ip_forwarding_enabled()) - { - $nethash{$node}{'gateway'} = xCAT::NetworkUtils->my_ip_in_subnet($net, $NM); - } - else - { - $nethash{$node}{'gateway'} = ''; - } - $nethash{$node}{'myselfgw'} = 1; - # For hwctrl commands, it is possible that this subroutine is called - # on MN instead of SN, if the hcp SN is not set - if (xCAT::Utils->isMN() && !$nethash{$node}{'gateway'}) - { - # does not have ip address in this subnet, - # use the node attribute 'xcatmaster' or site.master - my @nodes = ("$node"); - my $sn = xCAT::ServiceNodeUtils->get_ServiceNode(\@nodes,"xcat","Node"); - my $snkey = (keys %{$sn})[0]; - my $gw = xCAT::NetworkUtils->getipaddr($snkey); - # two possible cases when this code is run: - # 1. flat cluster: ip forwarding is not enabled on MN - # 2. hw ctrl in hierarchy cluster, in which HCP SN is not set - # in either case, MN itself should not be the gateway - if (xCAT::NetworkUtils->thishostisnot($gw)) { - $nethash{$node}{'gateway'} = $gw; - } - } - - } - next; + if(xCAT::NetworkUtils->ishostinsubnet($IP, $NM, $net)) + { + # fill in the hash - + foreach my $attr (@attrnames) { + if ( defined($_->{$attr}) ) { + $nethash{$node}{$attr} = $_->{$attr}; + } + } + if($nethash{$node}{'gateway'} eq '') + { + if(xCAT::NetworkUtils->ip_forwarding_enabled()) + { + $nethash{$node}{'gateway'} = xCAT::NetworkUtils->my_ip_in_subnet($net, $NM); + } + else + { + $nethash{$node}{'gateway'} = ''; + } + $nethash{$node}{'myselfgw'} = 1; + # For hwctrl commands, it is possible that this subroutine is called + # on MN instead of SN, if the hcp SN is not set + if (xCAT::Utils->isMN() && !$nethash{$node}{'gateway'}) + { + # does not have ip address in this subnet, + # use the node attribute 'xcatmaster' or site.master + my @nodes = ("$node"); + my $sn = xCAT::ServiceNodeUtils->get_ServiceNode(\@nodes,"xcat","Node"); + my $snkey = (keys %{$sn})[0]; + my $gw = xCAT::NetworkUtils->getipaddr($snkey); + # two possible cases when this code is run: + # 1. flat cluster: ip forwarding is not enabled on MN + # 2. hw ctrl in hierarchy cluster, in which HCP SN is not set + # in either case, MN itself should not be the gateway + if (xCAT::NetworkUtils->thishostisnot($gw)) { + $nethash{$node}{'gateway'} = $gw; } + } + + } + next; + } - } + } - } #end - for each node + } #end - for each node - return %nethash; + return %nethash; } #---------------------------------------------------------------------------- @@ -2054,7 +2054,7 @@ sub getNetwkInfo Error: Example: - To parse the access_tabentry field + To parse the access_tabentry field my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, $this_attr->{access_tabentry}, \%tabentry); @@ -2541,14 +2541,14 @@ sub getcecchildren foreach (@{$PARENT_CHILDREN_CEC{$parent}}) { push @children, $_; } - return \@children; - } + return \@children; + } } else { # already built the HASH if (exists($PARENT_CHILDREN_CEC{$parent})) { foreach (@{$PARENT_CHILDREN_CEC{$parent}}) { push @children, $_; } - return \@children; + return \@children; } } return undef; From 8ea19fd19378167d57096a530134fbba3ba7cd19 Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Fri, 28 Aug 2015 22:16:17 +0000 Subject: [PATCH 2/4] [perl-xCAT] Remove extraneous space in DBobjUtils.pm --- perl-xCAT/xCAT/DBobjUtils.pm | 302 +++++++++++++++++------------------ 1 file changed, 151 insertions(+), 151 deletions(-) diff --git a/perl-xCAT/xCAT/DBobjUtils.pm b/perl-xCAT/xCAT/DBobjUtils.pm index 3499b2ce3..c5622cd0a 100755 --- a/perl-xCAT/xCAT/DBobjUtils.pm +++ b/perl-xCAT/xCAT/DBobjUtils.pm @@ -127,7 +127,7 @@ sub getObjectsOfType =head3 getobjattrs - Get data from tables + Get data from tables $type_hash: objectname=>objtype hash $attrs_ref: only get the specific attributes, @@ -157,10 +157,10 @@ sub getobjattrs @attrs = @{shift()}; } my %typehash = %$ref_hash; - + my %tableattrs; my %tabhash; - + # get a list of object names for each type my %objtypelist; foreach my $objname (sort (keys %typehash)) { @@ -168,13 +168,13 @@ sub getobjattrs # $objtypelist{$typehash{$objname}}=$objname; push @{$objtypelist{$typehash{$objname}}}, $objname; } - + # go through each object type and look up all the info for each object foreach my $objtype (keys %objtypelist) { - - # only do node type for now + + # only do node type for now if ($objtype eq 'node') { - # find the list of tables and corresponding attrs + # find the list of tables and corresponding attrs # - for this object type # get the object type decription from Schema.pm my $datatype = $xCAT::Schema::defspec{$objtype}; @@ -185,7 +185,7 @@ sub getobjattrs next; # This attribute is not needed } } - + # table_attr is the attr that actually appears in the # table which could possibly be different then the attr # used in the node def @@ -195,8 +195,8 @@ sub getobjattrs push @{$tableattrs{$lookup_table}}, $table_attr; } } - - # foreach table look up the list of attrs for this + + # foreach table look up the list of attrs for this # list of object names foreach my $table (keys %tableattrs) { # open the table @@ -208,11 +208,11 @@ sub getobjattrs xCAT::MsgUtils->message("E", $rsp, $::callback); next; } - + my @objlist = @{$objtypelist{$objtype}}; - + my $rec = $thistable->getNodesAttribs(\@objlist, @{$tableattrs{$table}}); - + # fill in %tabhash with any values that are set foreach my $n (@objlist) { my $tmp1=$rec->{$n}->[0]; @@ -276,7 +276,7 @@ sub getobjdefs } @::foundTableList = (); - + if ($::ATTRLIST eq "none") { # just return the list of obj names foreach my $objname (sort (keys %typehash)) @@ -287,7 +287,7 @@ sub getobjdefs return %objhash; } - # see if we need to get any objects of type 'node' + # see if we need to get any objects of type 'node' my $getnodes=0; foreach my $objname (keys %typehash) { if ($typehash{$objname} eq 'node') { @@ -370,7 +370,7 @@ sub getobjdefs foreach my $objname (sort @{$type_obj{$objtype}}) { if (@TableRowArray) { my $foundinfo = 0; - foreach (@TableRowArray) { + foreach (@TableRowArray) { if ($_->{name} eq $objname ) { if ($_->{key}) { @@ -446,7 +446,7 @@ sub getobjdefs { my $ent; my $attr = $this_attr->{attr_name}; - + # skip the key attr ??? if ($attr eq $objkey) { @@ -456,17 +456,17 @@ sub getobjdefs if ($getnodes) { if (scalar(@attrs) > 0 && !grep(/^$attr$/, @attrs)) { next; - } + } } - + # OK - get the info needed to access the DB table # - i.e. table name, key name, attr names - + # need the actual table attr name corresponding # to the object attr name # ex. noderes.nfsdir my ($tab, $tabattr) = split('\.', $this_attr->{tabentry}); - + foreach my $objname (sort @{$type_obj{$objtype}}) { # get table lookup info from Schema.pm # !!!! some tables depend on the value of certain attrs @@ -480,13 +480,13 @@ sub getobjdefs # to match then try the next only_if value next if ( !($objhash{$objname}{$check_attr} =~ /\b$check_value\b/) ); } - - + + $objhash{$objname}{'objtype'} = $objtype; my %tabentry = (); # def commands need to support multiple keys in one table # the subroutine parse_access_tabentry is used for supporting multiple keys - my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, + my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, $this_attr->{access_tabentry}, \%tabentry); if ($rc != 0) { @@ -506,7 +506,7 @@ sub getobjdefs { # Check whether the attribute is already in %tabhash # The %tabhash is for performance considerations - if ( ($lookup_attr eq 'node') && ($objtype eq 'node') ){ + if ( ($lookup_attr eq 'node') && ($objtype eq 'node') ){ if (defined($tabhash{$lookup_table}{$objname}{$tabattr})) { if ($verbose == 1) { @@ -523,7 +523,7 @@ sub getobjdefs last; } elsif (! defined($tabhash{$lookup_table}{$objname}{"$tabattr"."_hassearched"})) { $notsearched = 1; - } + } } else { $notsearched = 1; } @@ -557,7 +557,7 @@ sub getobjdefs my @lookup_attrs = keys %{$tabentry{'lookup_attrs'}}; $objhash{$objname}{$attr} = "$rowent->{$tabattr}\t(Table:$lookup_table - Key: @lookup_attrs - Column:$tabattr)"; } - else + else { $objhash{$objname}{$attr} = $rowent->{$tabattr}; } @@ -572,7 +572,7 @@ sub getobjdefs } } - + } #foreach my $objtype return %objhash; @@ -593,7 +593,7 @@ sub getobjdefs Example: call as follows - my @TableRowArray= xCAT::DBobjUtils->getDBtable($tablename); + my @TableRowArray= xCAT::DBobjUtils->getDBtable($tablename); Comments: @@ -721,7 +721,7 @@ sub setobjdefs # Get the names of the attrs stored in monitoring table # get the object type decription from Schema.pm my $datatype = $xCAT::Schema::defspec{$type}; - + # get a list of valid attr names # for this type object my @attrlist; @@ -749,9 +749,9 @@ sub setobjdefs return 1; } - my %keyhash; + my %keyhash; my %updates; - + foreach my $attr (keys %{$objhash{$objname}}) { my $val; @@ -822,7 +822,7 @@ sub setobjdefs $monsettable->setAttribs(\%keyhash, \%updates); } } - + $montable->commit; $monsettable->commit; next; @@ -907,10 +907,10 @@ sub setobjdefs if ( $val eq "") { # delete the line $thistable->delEntries(\%keyhash); } else { # change the attr - + my %updates; $updates{value} = $val; - + my ($rc, $str) = $thistable->setAttribs(\%keyhash, \%updates); if (!defined($rc)) { @@ -984,7 +984,7 @@ sub setobjdefs } next; } - push(@attrprovided, $attr); + push(@attrprovided, $attr); } # we need to figure out what table to @@ -1082,7 +1082,7 @@ sub setobjdefs my $ntab; ($ntab, $::tabattr) = split('\.', $this_attr->{tabentry}); - my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, + my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, $this_attr->{access_tabentry}, \%tabentry); if ($rc != 0) { @@ -1097,7 +1097,7 @@ sub setobjdefs # the key is 'lookup_attrs' foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) { - $allupdates{$lookup_table}{$objname}{$attr_name}{'lookup_attrs'}{$lookup_attr} + $allupdates{$lookup_table}{$objname}{$attr_name}{'lookup_attrs'}{$lookup_attr} =$tabentry{'lookup_attrs'}{$lookup_attr}; } } @@ -1108,12 +1108,12 @@ sub setobjdefs my $val; my $delim = ','; - if(($type eq 'group') && ($DBattrvals{$objname}{'grouptype'} eq 'dynamic')) + if(($type eq 'group') && ($DBattrvals{$objname}{'grouptype'} eq 'dynamic')) { # dynamic node group selection string use "::" as delimiter $delim = '::'; } - + if ($::plus_option) { @@ -1202,7 +1202,7 @@ sub setobjdefs # the key is 'tabattrs' $allupdates{$lookup_table}{$objname}{$attr_name}{'tabattrs'}{$::tabattr} = $val; $setattrs=1; - + push(@setattrlist, $attr_name); } # end - foreach attribute @@ -1245,8 +1245,8 @@ my $tt = $invalidattr->{$att}->{valid}; } # end - foreach object #==========================================================# #%allupdates structure: -# for command: chdef -t node -o node1 groups=all -# usercomment=ddee passwd.HMC=HMC +# for command: chdef -t node -o node1 groups=all +# usercomment=ddee passwd.HMC=HMC # passwd.admin=cluster passwd.general=abc123 # the %allupdates will be: #0 'ppcdirect' @@ -1288,11 +1288,11 @@ my $tt = $invalidattr->{$att}->{valid}; # - handles all except site, monitoring & monsetting for now if ($setattrs) { foreach my $table (keys %allupdates) { - + # get the keys for this table my $schema = xCAT::Table->getTableSchema($table); my $keys = $schema->{keys}; - + # open the table my $thistable = xCAT::Table->new($table, -create => 1, -autocommit => 0); if (!$thistable) { @@ -1301,7 +1301,7 @@ my $tt = $invalidattr->{$att}->{valid}; xCAT::MsgUtils->message("E", $rsp, $::callback); return 1; } - + # Special case for the postscripts table # Does not set the postscripts to the postscripts table # if the postscripts already in xcatdefaults @@ -1332,7 +1332,7 @@ my $tt = $invalidattr->{$att}->{valid}; next; } my @newps; - if (defined($allupdates{$table}{$obj}{'postscripts'}) + if (defined($allupdates{$table}{$obj}{'postscripts'}) && defined($allupdates{$table}{$obj}{'postscripts'}{'tabattrs'}{'postscripts'})) { foreach my $tempps (split(/,/, $allupdates{$table}{$obj}{'postscripts'}{'tabattrs'}{'postscripts'})) { if (grep(/^$tempps$/, @xcatdefps)) { @@ -1346,7 +1346,7 @@ my $tt = $invalidattr->{$att}->{valid}; $allupdates{$table}{$obj}{'postscripts'}{'tabattrs'}{'postscripts'} = join(',', @newps); } my @newpbs; - if (defined($allupdates{$table}{$obj}{'postbootscripts'}) + if (defined($allupdates{$table}{$obj}{'postbootscripts'}) && defined($allupdates{$table}{$obj}{'postbootscripts'}{'tabattrs'}{'postbootscripts'})) { foreach my $temppbs (split(/,/, $allupdates{$table}{$obj}{'postbootscripts'}{'tabattrs'}{'postbootscripts'})) { if (grep(/^$temppbs$/, @xcatdefpbs)) { @@ -1379,7 +1379,7 @@ my $tt = $invalidattr->{$att}->{valid}; next ROW; } } - + if ($firsttime) { # lookup keys in %hashkey # ex. $keyhash{'hcp'} = node1 @@ -1391,8 +1391,8 @@ my $tt = $invalidattr->{$att}->{valid}; # check if the look_attrs is the same as the %keyhash foreach my $key (keys %{$allupdates{$table}{$obj}{$row}{'lookup_attrs'}}) { # The lookup_attrs can be different for tables with more than one keys such as ppcdirect - if ((scalar(keys %keyhash) != scalar(keys %{$allupdates{$table}{$obj}{$row}{'lookup_attrs'}})) - || !defined($keyhash{$key}) + if ((scalar(keys %keyhash) != scalar(keys %{$allupdates{$table}{$obj}{$row}{'lookup_attrs'}})) + || !defined($keyhash{$key}) ||($keyhash{$key} ne $allupdates{$table}{$obj}{$row}{'lookup_attrs'}{$key})) { # different keys, set the existing attributes into database # update the %keyhash and clean up the %updates hash @@ -1407,7 +1407,7 @@ my $tt = $invalidattr->{$att}->{valid}; } } } - + # set values in %updates # ex. $updates{'groups'} = 'all,lpar' foreach my $attr (keys %{$allupdates{$table}{$obj}{$row}{'tabattrs'}}) { @@ -1528,7 +1528,7 @@ sub rmobjdefs # put this info in a hash - we'll process it later - below foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) { - $tablehash{$lookup_table}{$objname}{$attr_name}{$lookup_attr} + $tablehash{$lookup_table}{$objname}{$attr_name}{$lookup_attr} = $tabentry{'lookup_attrs'}{$lookup_attr}; } @@ -1689,7 +1689,7 @@ sub readFileInput $l =~ /^(.*):(.*?)$/; ($objectname, $junk2) = ($1, $2); - # if $junk2 is defined or there's an = + # if $junk2 is defined or there's an = if ($junk2 || grep(/=/, $objectname)) { @@ -1794,7 +1794,7 @@ sub readFileInput Error: Example: To use: - - create hash for objectname and and attr values (need group + - create hash for objectname and and attr values (need group name (object), and grouptype & members attr values at a minimum.) @@ -1971,7 +1971,7 @@ sub getNetwkInfo my ($ia, $ib, $ic, $id) = split('\.', $IP); # check the entries of the networks table - # - if the bitwise AND of the IP and the netmask gives you + # - if the bitwise AND of the IP and the netmask gives you # the "net" name then that is the entry you want. foreach (@TableRowArray) { my $NM = $_->{'mask'}; @@ -1981,7 +1981,7 @@ sub getNetwkInfo if(xCAT::NetworkUtils->ishostinsubnet($IP, $NM, $net)) { - # fill in the hash - + # fill in the hash - foreach my $attr (@attrnames) { if ( defined($_->{$attr}) ) { $nethash{$node}{$attr} = $_->{$attr}; @@ -2016,11 +2016,11 @@ sub getNetwkInfo $nethash{$node}{'gateway'} = $gw; } } - + } next; } - + } } #end - for each node @@ -2036,7 +2036,7 @@ sub getNetwkInfo Arguments: $objname: objectname=>objtype hash $access_tabentry: the access_tabentry defined in Schema.pm - $tabentry_ref: return the parsed result through this hash ref + $tabentry_ref: return the parsed result through this hash ref The structure of the hash is: { 'lookup_tables' => @@ -2099,7 +2099,7 @@ sub parse_access_tabentry() if ($lookup_type eq 'attr') { # TODO: may need to update in the future - # for now, the "val" in attr:val in + # for now, the "val" in attr:val in # Schema.pm can only be the object name # In the future, even if we need to change here, # be caution about the performance @@ -2109,7 +2109,7 @@ sub parse_access_tabentry() elsif ($lookup_type eq 'str') { $tabentry_ref->{'lookup_attrs'}->{$lookup_attr} = $lookup_data; - } + } else { my $rsp; @@ -2132,9 +2132,9 @@ sub parse_access_tabentry() if specified port, it will just return nodes within the port. Globals: %PPCHASH - HASH of nodename -> array of ip addresses - where the nodetype is fsp or bpa + where the nodetype is fsp or bpa Error: - $::RUNCMD_RC = 1; + $::RUNCMD_RC = 1; Writes error to syslog Example: $c1 = getchildren($nodetocheck); @@ -2162,8 +2162,8 @@ sub getchildren my $ppctab = xCAT::Table->new( 'ppc' ); unless ($ppctab) { # cannot open the table return with error xCAT::MsgUtils->message('S', "getchildren:Unable to open ppc table.\n"); - $::RUNCMD_RC = 1; - return undef; + $::RUNCMD_RC = 1; + return undef; } my @ps = $ppctab->getAllNodeAttribs(['node','parent','nodetype','hcp']); foreach my $entry ( @ps ) { @@ -2173,17 +2173,17 @@ sub getchildren if ( $p and $c) { if ($t) { # the nodetype exists in the ppc table, use it if ( $t eq 'fsp' or $t eq 'bpa') { - # build hash of ppc.parent -> ppc.node + # build hash of ppc.parent -> ppc.node push @{$PPCHASH{$p}}, $c; - } + } elsif ($t eq 'blade') { push @{$PPCHASH{$c}}, $entry->{hcp}; } - } else { # go look in the nodetype table to find nodetype + } else { # go look in the nodetype table to find nodetype my $type = getnodetype($c, "ppc"); if ( $type eq 'fsp' or $type eq 'bpa') { - # build hash of ppc.parent -> ppc.node + # build hash of ppc.parent -> ppc.node push @{$PPCHASH{$p}}, $c; } elsif ($type eq "blade") { @@ -2192,7 +2192,7 @@ sub getchildren } } # not $p and $c } - # Find parent in the hash and build return values + # Find parent in the hash and build return values foreach (@{$PPCHASH{$parent}}) { push @children, $_; } @@ -2208,12 +2208,12 @@ sub getchildren { return \@children; } else { - if (@children) { + if (@children) { my $vpdtab = xCAT::Table->new( 'vpd' ); unless ($vpdtab) { # cannot open the table return with error xCAT::MsgUtils->message('S', "getchildren:Unable to open vpd table.\n"); - $::RUNCMD_RC = 1; - return undef; + $::RUNCMD_RC = 1; + return undef; } my $sides = $vpdtab->getNodesAttribs(\@children, ['side']); if(!$sides) @@ -2229,7 +2229,7 @@ sub getchildren } } return \@children_port; - } else { # no children + } else { # no children return undef; } } @@ -2239,16 +2239,16 @@ sub getchildren =head3 getnodetype Query ppc table, if no type found query nodetype table Arguments: - An array of nodenames or 1 nodename + An array of nodenames or 1 nodename Returns: - If the input is an array, it returns a hash, + If the input is an array, it returns a hash, for the nodes that can't get node type, it will be 'node' => undef; If the input is not an array, it returns the value of type, for the node that can't get node type, it will be undef; Globals: %NODETYPEHASH Error: - $::RUNCMD_RC = 1; + $::RUNCMD_RC = 1; Errors written to syslog Example: $type = xCAT::DBobjUtils->getnodetype($node, "ppc"); @@ -2273,8 +2273,8 @@ sub getnodetype my @tabletype = qw(ppc zvm); my %typehash; my %tablehash; - $::RUNCMD_RC = 0; - + $::RUNCMD_RC = 0; + my @failnodes; my @failnodes1; ###################################################################### @@ -2283,17 +2283,17 @@ sub getnodetype ###################################################################### if ($table) { my $nodetypetab = xCAT::Table->new( $table ); - unless ($nodetypetab) { + unless ($nodetypetab) { xCAT::MsgUtils->message('S', "getnodetype:Unable to open $table table.\n"); - $::RUNCMD_RC = 1; + $::RUNCMD_RC = 1; if ( $nodes =~ /^ARRAY/) { foreach my $tn (@$nodes) { $typehash{$tn} = undef; } } else { - $typehash{$nodes} = undef; - } - return \%typehash; + $typehash{$nodes} = undef; + } + return \%typehash; } ############################################ # if the input node arg is an array, @@ -2303,21 +2303,21 @@ sub getnodetype my $nodetypes = $nodetypetab->getNodesAttribs($nodes, ['nodetype']); foreach my $tn (@$nodes) { my $gottype = $nodetypes->{$tn}->[0]->{'nodetype'}; - if ( $gottype ) { + if ( $gottype ) { $NODETYPEHASH{$tn} = $gottype; - $typehash{$tn} = $gottype; + $typehash{$tn} = $gottype; } else { push @failnodes, $tn; } } ################################################ - # for the failed nodes, go to nodetype table + # for the failed nodes, go to nodetype table ################################################ if ( @failnodes ) { my $typetable = xCAT::Table->new( 'nodetype' ); unless ($typetable) { # cannot open the table return with error xCAT::MsgUtils->message('S', "getnodetype:Unable to open nodetype table.\n"); - $::RUNCMD_RC = 1; + $::RUNCMD_RC = 1; foreach my $tn (@failnodes) { $typehash{$tn} = undef; } @@ -2329,30 +2329,30 @@ sub getnodetype $typehash{$tn} = $nodetypes->{$tn}->[0]->{'nodetype'}; } else { push @failnodes1, $tn; - $typehash{$tn} = undef; + $typehash{$tn} = undef; } ################################################## # give error msg for the nodes can't get nodetype ################################################## - } + } if ( @failnodes1 ) { my $nodelist = join(",", @failnodes1); xCAT::MsgUtils->message('S', "getnodetype:Can't find these nodes' type: $nodelist.\n"); - } - } - } + } + } + } ##################### # return the result - ##################### + ##################### return \%typehash; - + } else { ############################################ # if the input node arg is not an array, # query table and use the global hash first ############################################ if ( $NODETYPEHASH{$nodes} ) { - return $NODETYPEHASH{$nodes}; + return $NODETYPEHASH{$nodes}; } else { my $typep = $nodetypetab->getNodeAttribs($nodes, ['nodetype']); if ( $typep->{nodetype} ) { @@ -2362,7 +2362,7 @@ sub getnodetype my $typetable = xCAT::Table->new( 'nodetype' ); unless ($typetable) { # cannot open the table return with error xCAT::MsgUtils->message('S', "getnodetype:Unable to open nodetype table.\n"); - $::RUNCMD_RC = 1; + $::RUNCMD_RC = 1; return undef; } my $typep = $typetable->getNodeAttribs($nodes, ['nodetype']); @@ -2371,7 +2371,7 @@ sub getnodetype return $typep->{nodetype}; } else { return undef; - } + } } } } @@ -2381,17 +2381,17 @@ sub getnodetype # if can't get anything from the specified table, go to nodetype table ###################################################################### my $nodetypetab = xCAT::Table->new( 'nodetype' ); - unless ($nodetypetab) { + unless ($nodetypetab) { xCAT::MsgUtils->message('S', "getnodetype:Unable to open $table table.\n"); - $::RUNCMD_RC = 1; + $::RUNCMD_RC = 1; if ( $nodes =~ /^ARRAY/) { foreach my $tn (@$nodes) { $typehash{$tn} = undef; } } else { - $typehash{$nodes} = undef; - } - return \%typehash; + $typehash{$nodes} = undef; + } + return \%typehash; } ############################################ # if the input node arg is an array, @@ -2411,17 +2411,17 @@ sub getnodetype } } } elsif (grep(/$gottype/, @tabletype)){ #if find ppc or zvm - $tablehash{ $tn } = $gottype; - } else { + $tablehash{ $tn } = $gottype; + } else { $NODETYPEHASH{ $tn } = $gottype; - $typehash{ $tn } = $gottype; - } + $typehash{ $tn } = $gottype; + } } else { $typehash{ $tn } = undef; } } ################################################ - # for the failed nodes, go to related tables + # for the failed nodes, go to related tables ################################################ if ( %tablehash ) { foreach my $ttable (@tabletype) { @@ -2430,13 +2430,13 @@ sub getnodetype if ($tablehash{$fnode} eq $ttable) { push @nodegroup, $fnode; } - } - next unless (@nodegroup); + } + next unless (@nodegroup); my $typetable = xCAT::Table->new( $ttable); unless ($typetable) { my $failnodes = join(",", @nodegroup); xCAT::MsgUtils->message('S', "getnodetype:Unable to open $ttable table, can't find $failnodes type.\n"); - $::RUNCMD_RC = 1; + $::RUNCMD_RC = 1; foreach (@nodegroup) { $typehash{$_} = undef; } @@ -2449,14 +2449,14 @@ sub getnodetype } else { $typehash{$fn} = undef; } - } + } } } - } - return \%typehash; + } + return \%typehash; } else { # if not an array if ( $NODETYPEHASH{$nodes} ) { - return $NODETYPEHASH{$nodes}; + return $NODETYPEHASH{$nodes}; } else { my $typep = $nodetypetab->getNodeAttribs($nodes, ["nodetype"]); if ( $typep->{nodetype} and !(grep(/$typep->{nodetype}/, @tabletype))) { @@ -2466,7 +2466,7 @@ sub getnodetype my $typetable = xCAT::Table->new( $typep->{nodetype} ); unless ($typetable) { xCAT::MsgUtils->message('S', "getnodetype:Unable to open nodetype table.\n"); - $::RUNCMD_RC = 1; + $::RUNCMD_RC = 1; return undef; } my $typep = $typetable->getNodeAttribs($nodes, ["nodetype"]); @@ -2475,7 +2475,7 @@ sub getnodetype return $typep->{nodetype}; } else { return undef; - } + } } } } @@ -2490,7 +2490,7 @@ sub getnodetype Returns: Array of cec hostnames Globals: - %PARENT_CHILDREN_CEC + %PARENT_CHILDREN_CEC Error: none Example: @@ -2513,8 +2513,8 @@ sub getcecchildren my $ppctab = xCAT::Table->new( 'ppc' ); unless ($ppctab) { # cannot open the table return with error xCAT::MsgUtils->message('S', "getcecchildren:Unable to open ppc table.\n"); - $::RUNCMD_RC = 1; - return undef; + $::RUNCMD_RC = 1; + return undef; } if ($ppctab) { @@ -2526,10 +2526,10 @@ sub getcecchildren if ( $p and $c) { if ($t) { # the nodetype exists in the ppc table, use it if ( $t eq 'cec') { - # build hash of ppc.parent -> ppc.node + # build hash of ppc.parent -> ppc.node push @{$PARENT_CHILDREN_CEC{$p}}, $c; - } - } else { # go look in the nodetype table to find nodetype + } + } else { # go look in the nodetype table to find nodetype my $type = getnodetype($c); if ( $type eq 'cec') { push @{$PARENT_CHILDREN_CEC{$p}}, $c; @@ -2537,9 +2537,9 @@ sub getcecchildren } } } - # find a match for the parent and build the return array + # find a match for the parent and build the return array foreach (@{$PARENT_CHILDREN_CEC{$parent}}) { - push @children, $_; + push @children, $_; } return \@children; } @@ -2556,7 +2556,7 @@ sub getcecchildren #------------------------------------------------------------------------------- =head3 judge_node - judge the node is a real FSP/BPA, + judge the node is a real FSP/BPA, use to distinguish if the data is defined in xCAT 2.5 or later Arguments: node name @@ -2578,19 +2578,19 @@ sub judge_node if (($node) && ($node =~ /xCAT::/)) { $node = shift; - } + } my $type = shift; my $flag = 0; my $parenttype; my $nodeparent; - my $ppctab = xCAT::Table->new( 'ppc' ); + my $ppctab = xCAT::Table->new( 'ppc' ); if ( $ppctab ) { $nodeparent = $ppctab->getNodeAttribs($node, ["parent"]); if ($nodeparent and $nodeparent->{parent}) { $parenttype = getnodetype($nodeparent->{parent}); } } - + if ($type =~ /^fsp$/) { if ($parenttype =~ /^cec$/) { @@ -2609,9 +2609,9 @@ sub judge_node { $flag = 0; } - } - - return $flag; + } + + return $flag; } @@ -2625,7 +2625,7 @@ sub judge_node nicsips.eth1=3.1.1.1|4.1.1.1 Arguments: - nicsattr value, like niccsips=eth0!1.1.1.1|2.1.1.1,eth1!3.1.1.1|4.1.1.1 + nicsattr value, like niccsips=eth0!1.1.1.1|2.1.1.1,eth1!3.1.1.1|4.1.1.1 nicnames: only return the value for specific nics, like "eth0,eth1" Returns: expanded format, like: @@ -2651,7 +2651,7 @@ sub expandnicsattr() } my $nicnames = shift; - my $ret; + my $ret; $nicstr =~ /^(.*?)=(.*?)$/; @@ -2662,9 +2662,9 @@ sub expandnicsattr() my $nicval=$2; # $nicarr[0]: eth0!1.1.1.1|2.1.1.1 - # $nicarr[1]: eth1!3.1.1.1|4.1.1.1 + # $nicarr[1]: eth1!3.1.1.1|4.1.1.1 my @nicarr = split(/,/, $nicval); - + foreach my $nicentry (@nicarr) { #nicentry: eth0!1.1.1.1|2.1.1.1 @@ -2703,13 +2703,13 @@ sub expandnicsattr() =head3 collapsenicsattr Collapse the nics related attributes into the database format, - for example, + for example, nicsips.eth0=1.1.1.1|2.1.1.1 nicsips.eth1=3.1.1.1|4.1.1.1 - + the collapsed format: nicsips=eth0!1.1.1.1|2.1.1.1,eth1!3.1.1.1|4.1.1.1 - + The collapse will be done against the hash %::FILEATTRS or %::CLIATTRS, remove the nicips.thx attributes from %::FILEATTRS or %::CLIATTRS, add the collapsed info nicips into %::FILEATTRS or %::CLIATTRS. @@ -2743,40 +2743,40 @@ sub collapsenicsattr() my %nicattrs = (); foreach my $nodeattr (keys %{$nodeattrhash}) - { + { # e.g nicips.eth0 # do not need to handle nic attributes without the postfix .ethx, # it will be overwritten by the attributes with the postfix .ethx, if ($nodeattr =~ /^(nic\w+)\.(.*)$/) - { + { if ($1 && $2) - { + { # chdef nicips.eth2= to remove the definition for eth2 # in this case, the $nodeattrhash->{'nicips.eth0'} is blank if ($nodeattrhash->{$nodeattr}) { # $nicattrs{nicips}{eth0} = "1.1.1.1|1.2.1.1" - $nicattrs{$1}{$2} = $nodeattrhash->{$nodeattr}; + $nicattrs{$1}{$2} = $nodeattrhash->{$nodeattr}; } # remove nicips.eth0 from the %::FILEATTRS delete $nodeattrhash->{$nodeattr}; - } - } - } + } + } + } # $nicattrs{'nicips'}{'eth0'} = "1.1.1.1|1.2.1.1" # $nicattrs{'nicips'}{'eth1'} = "2.1.1.1|2.2.1.1" foreach my $nicattr (keys %nicattrs) - { + { my @tmparray = (); foreach my $nicname (keys %{$nicattrs{$nicattr}}) - { + { # eth0!1.1.1.1|1.2.1.1 push @tmparray, "$nicname!$nicattrs{$nicattr}{$nicname}"; - } + } # eth0!1.1.1.1|1.2.1.1,eth1!2.1.1.1|2.2.1.1 $nodeattrhash->{$nicattr} = join(',', @tmparray); - } + } } 1; From c52154d62a05249bdcc0de8dee6cda86c0c688f7 Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Fri, 28 Aug 2015 22:40:37 +0000 Subject: [PATCH 3/4] [perl-xCAT] Fix indentation in DBobjUtils.pm --- perl-xCAT/xCAT/DBobjUtils.pm | 342 +++++++++++++++++------------------ 1 file changed, 171 insertions(+), 171 deletions(-) diff --git a/perl-xCAT/xCAT/DBobjUtils.pm b/perl-xCAT/xCAT/DBobjUtils.pm index c5622cd0a..944b44d03 100755 --- a/perl-xCAT/xCAT/DBobjUtils.pm +++ b/perl-xCAT/xCAT/DBobjUtils.pm @@ -172,8 +172,8 @@ sub getobjattrs # go through each object type and look up all the info for each object foreach my $objtype (keys %objtypelist) { - # only do node type for now - if ($objtype eq 'node') { + # only do node type for now + if ($objtype eq 'node') { # find the list of tables and corresponding attrs # - for this object type # get the object type decription from Schema.pm @@ -433,17 +433,17 @@ sub getobjdefs last; } # end if($entry-> } # end foreach my $entry - } # end if(@TableTowArray - } # end foreach my $objname + } # end if(@TableTowArray + } # end foreach my $objname } else { # get the object type decription from Schema.pm my $datatype = $xCAT::Schema::defspec{$objtype}; # get the key to look for, for this object type my $objkey = $datatype->{'objkey'}; - # go through the list of valid attrs - foreach my $this_attr (@{$datatype->{'attrs'}}) - { + # go through the list of valid attrs + foreach my $this_attr (@{$datatype->{'attrs'}}) + { my $ent; my $attr = $this_attr->{attr_name}; @@ -475,10 +475,10 @@ sub getobjdefs # in for some attrs. if (exists($this_attr->{only_if})) { - my ($check_attr, $check_value) = split('\=', $this_attr->{only_if}); - # if the object value is not the value we need - # to match then try the next only_if value - next if ( !($objhash{$objname}{$check_attr} =~ /\b$check_value\b/) ); + my ($check_attr, $check_value) = split('\=', $this_attr->{only_if}); + # if the object value is not the value we need + # to match then try the next only_if value + next if ( !($objhash{$objname}{$check_attr} =~ /\b$check_value\b/) ); } @@ -490,11 +490,11 @@ sub getobjdefs $this_attr->{access_tabentry}, \%tabentry); if ($rc != 0) { - my $rsp; - $rsp->{data}->[0] = - "access_tabentry \'$this_attr->{access_tabentry}\' is not valid."; - xCAT::MsgUtils->message("E", $rsp, $::callback); - next; + my $rsp; + $rsp->{data}->[0] = + "access_tabentry \'$this_attr->{access_tabentry}\' is not valid."; + xCAT::MsgUtils->message("E", $rsp, $::callback); + next; } # # Only allow one table in the access_tabentry @@ -552,19 +552,19 @@ sub getobjdefs } if ($match == 1) { - if ($verbose == 1) - { - my @lookup_attrs = keys %{$tabentry{'lookup_attrs'}}; - $objhash{$objname}{$attr} = "$rowent->{$tabattr}\t(Table:$lookup_table - Key: @lookup_attrs - Column:$tabattr)"; - } - else - { - $objhash{$objname}{$attr} = $rowent->{$tabattr}; - } - if (defined $chname_ref) { - push @{$chname_ref->{$lookup_table}}, ($tabentry{'lookup_attrs'}, (keys %{$tabentry{'lookup_attrs'}}) [0]); - } - } #end if ($match... + if ($verbose == 1) + { + my @lookup_attrs = keys %{$tabentry{'lookup_attrs'}}; + $objhash{$objname}{$attr} = "$rowent->{$tabattr}\t(Table:$lookup_table - Key: @lookup_attrs - Column:$tabattr)"; + } + else + { + $objhash{$objname}{$attr} = $rowent->{$tabattr}; + } + if (defined $chname_ref) { + push @{$chname_ref->{$lookup_table}}, ($tabentry{'lookup_attrs'}, (keys %{$tabentry{'lookup_attrs'}}) [0]); + } + } #end if ($match... } #end foreach } # end if (defined... } #end if ($intabhash... @@ -593,7 +593,7 @@ sub getobjdefs Example: call as follows - my @TableRowArray= xCAT::DBobjUtils->getDBtable($tablename); + my @TableRowArray= xCAT::DBobjUtils->getDBtable($tablename); Comments: @@ -641,11 +641,11 @@ sub getDBtable if (@rows) { - return @rows; + return @rows; } else { - return undef; + return undef; } } @@ -686,7 +686,7 @@ sub setobjdefs my $setattrs=0; # get the attr=vals for these objects from the DB - if any - # - so we can figure out where to put additional attrs + # - so we can figure out where to put additional attrs # The getobjdefs call was in the foreach loop, # it caused mkdef/chdef performance issue, # so it is moved out of the foreach loop @@ -1089,8 +1089,8 @@ sub setobjdefs my $rsp; $rsp->{data}->[0] = "access_tabentry \'$this_attr->{access_tabentry}\' is not valid."; - xCAT::MsgUtils->message("E", $rsp, $::callback); - next; + xCAT::MsgUtils->message("E", $rsp, $::callback); + next; } $lookup_table = $tabentry{'lookup_table'}; # Set the lookup criteria for this attribute into %allupdates @@ -1130,8 +1130,8 @@ sub setobjdefs { push @DBattrarray, $objattr; } - } - $val = join($delim, @DBattrarray); + } + $val = join($delim, @DBattrarray); } else { @@ -1161,11 +1161,11 @@ sub setobjdefs my $rsp; $rsp->{data}->[0] = "$objname is not a member of \'$em\'."; xCAT::MsgUtils->message("W", $rsp, $::callback); - } else { + } else { my $rsp; $rsp->{data}->[0] = "$em is not in the attribute of \'$attr_name\' for the \'$objname\' definition."; xCAT::MsgUtils->message("W", $rsp, $::callback); - } + } } } # make a new list without the one specified @@ -1336,12 +1336,12 @@ my $tt = $invalidattr->{$att}->{valid}; && defined($allupdates{$table}{$obj}{'postscripts'}{'tabattrs'}{'postscripts'})) { foreach my $tempps (split(/,/, $allupdates{$table}{$obj}{'postscripts'}{'tabattrs'}{'postscripts'})) { if (grep(/^$tempps$/, @xcatdefps)) { - my $rsp; - $rsp->{data}->[0] = "$obj: postscripts \'$tempps\' is already included in the \'xcatdefaults\'."; - xCAT::MsgUtils->message("E", $rsp, $::callback); - } else { - push @newps, $tempps; - } + my $rsp; + $rsp->{data}->[0] = "$obj: postscripts \'$tempps\' is already included in the \'xcatdefaults\'."; + xCAT::MsgUtils->message("E", $rsp, $::callback); + } else { + push @newps, $tempps; + } } $allupdates{$table}{$obj}{'postscripts'}{'tabattrs'}{'postscripts'} = join(',', @newps); } @@ -1358,7 +1358,7 @@ my $tt = $invalidattr->{$att}->{valid}; } } $allupdates{$table}{$obj}{'postbootscripts'}{'tabattrs'}{'postbootscripts'} = join(',', @newpbs); - } + } } } @@ -1515,8 +1515,8 @@ sub rmobjdefs my $rsp; $rsp->{data}->[0] = "access_tabentry \'$this_attr->{access_tabentry}\' is not valid."; - xCAT::MsgUtils->message("E", $rsp, $::callback); - next; + xCAT::MsgUtils->message("E", $rsp, $::callback); + next; } # Only allow one table in the access_tabentry @@ -1818,7 +1818,7 @@ sub getGroupMembers # set 'static' as the dafault of nodetype if (!defined($objhash{$objectname}{'grouptype'}) || - $objhash{$objectname}{'grouptype'} eq "") { + $objhash{$objectname}{'grouptype'} eq "") { $objhash{$objectname}{'grouptype'} = 'static'; } @@ -2037,16 +2037,16 @@ sub getNetwkInfo $objname: objectname=>objtype hash $access_tabentry: the access_tabentry defined in Schema.pm $tabentry_ref: return the parsed result through this hash ref - The structure of the hash is: - { - 'lookup_tables' => - 'lookup_attrs' => - { - 'attr1' => 'val1' - 'attr2' => 'val2' - ... - } - } + The structure of the hash is: + { + 'lookup_tables' => + 'lookup_attrs' => + { + 'attr1' => 'val1' + 'attr2' => 'val2' + ... + } + } Returns: 0 - success 1 - failed @@ -2096,28 +2096,28 @@ sub parse_access_tabentry() return 1; } - if ($lookup_type eq 'attr') - { - # TODO: may need to update in the future - # for now, the "val" in attr:val in - # Schema.pm can only be the object name - # In the future, even if we need to change here, - # be caution about the performance - # looking up table is time consuming - $tabentry_ref->{'lookup_attrs'}->{$lookup_attr} = $objname; - } - elsif ($lookup_type eq 'str') - { - $tabentry_ref->{'lookup_attrs'}->{$lookup_attr} = $lookup_data; - } - else - { - my $rsp; - $rsp->{data}->[0] = + if ($lookup_type eq 'attr') + { + # TODO: may need to update in the future + # for now, the "val" in attr:val in + # Schema.pm can only be the object name + # In the future, even if we need to change here, + # be caution about the performance + # looking up table is time consuming + $tabentry_ref->{'lookup_attrs'}->{$lookup_attr} = $objname; + } + elsif ($lookup_type eq 'str') + { + $tabentry_ref->{'lookup_attrs'}->{$lookup_attr} = $lookup_data; + } + else + { + my $rsp; + $rsp->{data}->[0] = "The access_tabentry \"$access_tabentry\" is not valid, the lookup type can only be 'attr' or 'str'."; - xCAT::MsgUtils->message("E", $rsp, $::callback); - return 1; - } + xCAT::MsgUtils->message("E", $rsp, $::callback); + return 1; + } } return 0; } @@ -2128,17 +2128,17 @@ sub parse_access_tabentry() single hostname optional port number Returns: - array of fsp/bpa hostnames (IPs) - if specified port, it will just return nodes within the port. + array of fsp/bpa hostnames (IPs) + if specified port, it will just return nodes within the port. Globals: %PPCHASH - HASH of nodename -> array of ip addresses - where the nodetype is fsp or bpa + where the nodetype is fsp or bpa Error: - $::RUNCMD_RC = 1; - Writes error to syslog + $::RUNCMD_RC = 1; + Writes error to syslog Example: - $c1 = getchildren($nodetocheck); - $c1 = getchildren($nodetocheck,$port); + $c1 = getchildren($nodetocheck); + $c1 = getchildren($nodetocheck,$port); Comments: none =cut @@ -2161,9 +2161,9 @@ sub getchildren if (!%PPCHASH) { my $ppctab = xCAT::Table->new( 'ppc' ); unless ($ppctab) { # cannot open the table return with error - xCAT::MsgUtils->message('S', "getchildren:Unable to open ppc table.\n"); - $::RUNCMD_RC = 1; - return undef; + xCAT::MsgUtils->message('S', "getchildren:Unable to open ppc table.\n"); + $::RUNCMD_RC = 1; + return undef; } my @ps = $ppctab->getAllNodeAttribs(['node','parent','nodetype','hcp']); foreach my $entry ( @ps ) { @@ -2171,25 +2171,25 @@ sub getchildren my $c = $entry->{node}; my $t = $entry->{nodetype}; if ( $p and $c) { - if ($t) { # the nodetype exists in the ppc table, use it - if ( $t eq 'fsp' or $t eq 'bpa') { - # build hash of ppc.parent -> ppc.node - push @{$PPCHASH{$p}}, $c; + if ($t) { # the nodetype exists in the ppc table, use it + if ( $t eq 'fsp' or $t eq 'bpa') { + # build hash of ppc.parent -> ppc.node + push @{$PPCHASH{$p}}, $c; + } + elsif ($t eq 'blade') { + push @{$PPCHASH{$c}}, $entry->{hcp}; + } + } else { # go look in the nodetype table to find nodetype + my $type = getnodetype($c, "ppc"); + if ( $type eq 'fsp' or $type eq 'bpa') + { + # build hash of ppc.parent -> ppc.node + push @{$PPCHASH{$p}}, $c; + } + elsif ($type eq "blade") { + push @{$PPCHASH{$c}}, $entry->{hcp}; + } } - elsif ($t eq 'blade') { - push @{$PPCHASH{$c}}, $entry->{hcp}; - } - } else { # go look in the nodetype table to find nodetype - my $type = getnodetype($c, "ppc"); - if ( $type eq 'fsp' or $type eq 'bpa') - { - # build hash of ppc.parent -> ppc.node - push @{$PPCHASH{$p}}, $c; - } - elsif ($type eq "blade") { - push @{$PPCHASH{$c}}, $entry->{hcp}; - } - } } # not $p and $c } # Find parent in the hash and build return values @@ -2208,30 +2208,30 @@ sub getchildren { return \@children; } else { - if (@children) { - my $vpdtab = xCAT::Table->new( 'vpd' ); - unless ($vpdtab) { # cannot open the table return with error - xCAT::MsgUtils->message('S', "getchildren:Unable to open vpd table.\n"); - $::RUNCMD_RC = 1; - return undef; - } - my $sides = $vpdtab->getNodesAttribs(\@children, ['side']); - if(!$sides) - { - return undef; - } - foreach my $n (@children) - { - my $nside = $sides->{$n}->[0]; - if ($nside->{side} =~ /$port/) - { - push @children_port, $n; + if (@children) { + my $vpdtab = xCAT::Table->new( 'vpd' ); + unless ($vpdtab) { # cannot open the table return with error + xCAT::MsgUtils->message('S', "getchildren:Unable to open vpd table.\n"); + $::RUNCMD_RC = 1; + return undef; } + my $sides = $vpdtab->getNodesAttribs(\@children, ['side']); + if(!$sides) + { + return undef; + } + foreach my $n (@children) + { + my $nside = $sides->{$n}->[0]; + if ($nside->{side} =~ /$port/) + { + push @children_port, $n; + } + } + return \@children_port; + } else { # no children + return undef; } - return \@children_port; - } else { # no children - return undef; - } } } #------------------------------------------------------------------------------- @@ -2239,7 +2239,7 @@ sub getchildren =head3 getnodetype Query ppc table, if no type found query nodetype table Arguments: - An array of nodenames or 1 nodename + An array of nodenames or 1 nodename Returns: If the input is an array, it returns a hash, for the nodes that can't get node type, it will be 'node' => undef; @@ -2251,10 +2251,10 @@ sub getchildren $::RUNCMD_RC = 1; Errors written to syslog Example: - $type = xCAT::DBobjUtils->getnodetype($node, "ppc"); - $type = xCAT::DBobjUtils->getnodetype($node); - $typerefer = xCAT::DBobjUtils->getnodetype(\@nodes, "PPC"); - $typerefer = xCAT::DBobjUtils->getnodetype(\@nodes); + $type = xCAT::DBobjUtils->getnodetype($node, "ppc"); + $type = xCAT::DBobjUtils->getnodetype($node); + $typerefer = xCAT::DBobjUtils->getnodetype(\@nodes, "PPC"); + $typerefer = xCAT::DBobjUtils->getnodetype(\@nodes); Comments: none =cut @@ -2494,7 +2494,7 @@ sub getnodetype Error: none Example: - @frame_members = getcecchildren($frame); + @frame_members = getcecchildren($frame); Comments: none =cut @@ -2512,9 +2512,9 @@ sub getcecchildren if (!%PARENT_CHILDREN_CEC) { my $ppctab = xCAT::Table->new( 'ppc' ); unless ($ppctab) { # cannot open the table return with error - xCAT::MsgUtils->message('S', "getcecchildren:Unable to open ppc table.\n"); - $::RUNCMD_RC = 1; - return undef; + xCAT::MsgUtils->message('S', "getcecchildren:Unable to open ppc table.\n"); + $::RUNCMD_RC = 1; + return undef; } if ($ppctab) { @@ -2524,17 +2524,17 @@ sub getcecchildren my $c = $entry->{node}; my $t = $entry->{nodetype}; if ( $p and $c) { - if ($t) { # the nodetype exists in the ppc table, use it - if ( $t eq 'cec') { - # build hash of ppc.parent -> ppc.node - push @{$PARENT_CHILDREN_CEC{$p}}, $c; - } - } else { # go look in the nodetype table to find nodetype - my $type = getnodetype($c); - if ( $type eq 'cec') { - push @{$PARENT_CHILDREN_CEC{$p}}, $c; - } - } + if ($t) { # the nodetype exists in the ppc table, use it + if ( $t eq 'cec') { + # build hash of ppc.parent -> ppc.node + push @{$PARENT_CHILDREN_CEC{$p}}, $c; + } + } else { # go look in the nodetype table to find nodetype + my $type = getnodetype($c); + if ( $type eq 'cec') { + push @{$PARENT_CHILDREN_CEC{$p}}, $c; + } + } } } # find a match for the parent and build the return array @@ -2566,7 +2566,7 @@ sub getcecchildren Error: none Example: - $result = judge_node($nodetocheck); + $result = judge_node($nodetocheck); Comments: none =cut @@ -2749,33 +2749,33 @@ sub collapsenicsattr() # it will be overwritten by the attributes with the postfix .ethx, if ($nodeattr =~ /^(nic\w+)\.(.*)$/) { - if ($1 && $2) - { - # chdef nicips.eth2= to remove the definition for eth2 - # in this case, the $nodeattrhash->{'nicips.eth0'} is blank - if ($nodeattrhash->{$nodeattr}) - { - # $nicattrs{nicips}{eth0} = "1.1.1.1|1.2.1.1" - $nicattrs{$1}{$2} = $nodeattrhash->{$nodeattr}; - } + if ($1 && $2) + { + # chdef nicips.eth2= to remove the definition for eth2 + # in this case, the $nodeattrhash->{'nicips.eth0'} is blank + if ($nodeattrhash->{$nodeattr}) + { + # $nicattrs{nicips}{eth0} = "1.1.1.1|1.2.1.1" + $nicattrs{$1}{$2} = $nodeattrhash->{$nodeattr}; + } - # remove nicips.eth0 from the %::FILEATTRS - delete $nodeattrhash->{$nodeattr}; - } + # remove nicips.eth0 from the %::FILEATTRS + delete $nodeattrhash->{$nodeattr}; + } } } # $nicattrs{'nicips'}{'eth0'} = "1.1.1.1|1.2.1.1" # $nicattrs{'nicips'}{'eth1'} = "2.1.1.1|2.2.1.1" foreach my $nicattr (keys %nicattrs) { - my @tmparray = (); - foreach my $nicname (keys %{$nicattrs{$nicattr}}) - { - # eth0!1.1.1.1|1.2.1.1 - push @tmparray, "$nicname!$nicattrs{$nicattr}{$nicname}"; - } - # eth0!1.1.1.1|1.2.1.1,eth1!2.1.1.1|2.2.1.1 - $nodeattrhash->{$nicattr} = join(',', @tmparray); + my @tmparray = (); + foreach my $nicname (keys %{$nicattrs{$nicattr}}) + { + # eth0!1.1.1.1|1.2.1.1 + push @tmparray, "$nicname!$nicattrs{$nicattr}{$nicname}"; + } + # eth0!1.1.1.1|1.2.1.1,eth1!2.1.1.1|2.2.1.1 + $nodeattrhash->{$nicattr} = join(',', @tmparray); } } From 189c4cfc4253fd08b1bb4b67e30fb3f1b0e77420 Mon Sep 17 00:00:00 2001 From: Samveen Gulati Date: Fri, 28 Aug 2015 23:21:49 +0000 Subject: [PATCH 4/4] [perl-xCAT] DBobjUtils.pm Formatting - Consistent placing of `{` --- perl-xCAT/xCAT/DBobjUtils.pm | 613 ++++++++++++----------------------- 1 file changed, 199 insertions(+), 414 deletions(-) diff --git a/perl-xCAT/xCAT/DBobjUtils.pm b/perl-xCAT/xCAT/DBobjUtils.pm index 944b44d03..1cbaeac1d 100755 --- a/perl-xCAT/xCAT/DBobjUtils.pm +++ b/perl-xCAT/xCAT/DBobjUtils.pm @@ -49,20 +49,16 @@ sub getObjectsOfType my @objlist; # special case for site table - if ($type eq 'site') - { + if ($type eq 'site') { push(@objlist, 'clustersite'); return @objlist; } # The database may be changed between getObjectsOfType calls # do not use cache %::saveObjList if --nocache is specified - if ($::saveObjList{$type} && !$::opt_nc) - { + if ($::saveObjList{$type} && !$::opt_nc) { @objlist = @{$::saveObjList{$type}}; - } - else - { + } else { # get the key for this type object # ex. for "network" type the key is "netname" @@ -75,11 +71,9 @@ sub getObjectsOfType my $table; my $tabkey; - foreach my $this_attr (@{$datatype->{'attrs'}}) - { + foreach my $this_attr (@{$datatype->{'attrs'}}) { my $attr = $this_attr->{attr_name}; - if ($attr eq $objkey) - { + if ($attr eq $objkey) { # get the table & key for to lookup # get the actual attr name to use in the table # - may be different then the attr name used for the object. @@ -92,25 +86,20 @@ sub getObjectsOfType # to the list of objects. my @TableRowArray = xCAT::DBobjUtils->getDBtable($table); - foreach (@TableRowArray) - { + foreach (@TableRowArray) { push(@objlist, $_->{$tabkey}); - } # if this is type "group" we need to check the nodelist table my @nodeGroupList=(); - if ($type eq 'group') - { + if ($type eq 'group') { my $table = "nodelist"; my @TableRowArray = xCAT::DBobjUtils->getDBtable($table); - foreach (@TableRowArray) - { + foreach (@TableRowArray) { my @tmplist = split(',', $_->{'groups'}); push(@nodeGroupList, @tmplist); } - foreach my $n (@nodeGroupList) - { + foreach my $n (@nodeGroupList) { if (!grep(/^$n$/, @objlist) ) { push(@objlist, $n); } @@ -270,8 +259,7 @@ sub getobjdefs my %typehash = %$hash_ref; my %tabhash; my @attrs; - if (ref($attrs_ref)) - { + if (ref($attrs_ref)) { @attrs = @$attrs_ref; } @@ -279,8 +267,7 @@ sub getobjdefs if ($::ATTRLIST eq "none") { # just return the list of obj names - foreach my $objname (sort (keys %typehash)) - { + foreach my $objname (sort (keys %typehash)) { my $type = $typehash{$objname}; $objhash{$objname}{'objtype'} = $type; } @@ -301,8 +288,7 @@ sub getobjdefs # values from when using 'only_if' - see below # - but this saves lots of time if ($getnodes) { - if (scalar(@attrs) > 0) # Only get specific attributes of the node - { + if (scalar(@attrs) > 0) { # Only get specific attributes of the node # find the onlyif key for the attributes REDO: my $datatype = $xCAT::Schema::defspec{'node'}; foreach my $this_attr (@{$datatype->{'attrs'}}) { @@ -316,9 +302,7 @@ sub getobjdefs } } %tabhash = xCAT::DBobjUtils->getobjattrs(\%typehash, \@attrs); - } - else - { + } else { %tabhash = xCAT::DBobjUtils->getobjattrs(\%typehash); } } @@ -333,13 +317,10 @@ sub getobjdefs if ($objtype eq 'site') { my @TableRowArray = xCAT::DBobjUtils->getDBtable('site'); foreach my $objname (sort @{$type_obj{$objtype}}) { - if (@TableRowArray) - { + if (@TableRowArray) { my $foundinfo = 0; - foreach (@TableRowArray) - { - if ($_->{key}) - { + foreach (@TableRowArray) { + if ($_->{key}) { if (defined($_->{value}) ) { $foundinfo++; if ($verbose == 1) { @@ -350,13 +331,10 @@ sub getobjdefs } } } - if ($foundinfo) - { + if ($foundinfo) { $objhash{$objname}{'objtype'} = 'site'; } - } - else - { + } else { my $rsp; $rsp->{data}->[0] ="Could not read the \'$objname\' object from the \'site\' table."; xCAT::MsgUtils->message("E", $rsp, $::callback); @@ -372,8 +350,7 @@ sub getobjdefs my $foundinfo = 0; foreach (@TableRowArray) { if ($_->{name} eq $objname ) { - if ($_->{key}) - { + if ($_->{key}) { if (defined($_->{value}) ) { $foundinfo++; if ($verbose == 1) { @@ -385,13 +362,10 @@ sub getobjdefs } } } - if ($foundinfo) - { + if ($foundinfo) { $objhash{$objname}{'objtype'} = 'monitoring'; } - } - else - { + } else { my $rsp; $rsp->{data}->[0] ="Could not read the \'$objname\' object from the \'monsetting\' table."; xCAT::MsgUtils->message("E", $rsp, $::callback); @@ -405,15 +379,11 @@ sub getobjdefs # performance is a big concern with the general logic my @TableRowArray = xCAT::DBobjUtils->getDBtable($objtype); foreach my $objname (sort @{$type_obj{$objtype}}) { - if (@TableRowArray) - { + if (@TableRowArray) { my $foundinfo = 0; - foreach my $entry (@TableRowArray) - { - if ($entry->{recid} eq $objname) - { - foreach my $k (keys %{$entry}) - { + foreach my $entry (@TableRowArray) { + if ($entry->{recid} eq $objname) { + foreach my $k (keys %{$entry}) { # recid is the object name, do not need to be in the attributes list if ($k eq 'recid') { next; } if (defined($entry->{$k}) ) { @@ -425,8 +395,7 @@ sub getobjdefs } } } - if ($foundinfo) - { + if ($foundinfo) { $objhash{$objname}{'objtype'} = $objtype; } # There should not be multiple entries with the same recid @@ -442,14 +411,12 @@ sub getobjdefs my $objkey = $datatype->{'objkey'}; # go through the list of valid attrs - foreach my $this_attr (@{$datatype->{'attrs'}}) - { + foreach my $this_attr (@{$datatype->{'attrs'}}) { my $ent; my $attr = $this_attr->{attr_name}; # skip the key attr ??? - if ($attr eq $objkey) - { + if ($attr eq $objkey) { next; } # skip the attributes that does not needed for node type @@ -473,8 +440,7 @@ sub getobjdefs # we need to look up attrs in the correct order or we will # not be able to determine what tables to look # in for some attrs. - if (exists($this_attr->{only_if})) - { + if (exists($this_attr->{only_if})) { my ($check_attr, $check_value) = split('\=', $this_attr->{only_if}); # if the object value is not the value we need # to match then try the next only_if value @@ -488,8 +454,7 @@ sub getobjdefs # the subroutine parse_access_tabentry is used for supporting multiple keys my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, $this_attr->{access_tabentry}, \%tabentry); - if ($rc != 0) - { + if ($rc != 0) { my $rsp; $rsp->{data}->[0] = "access_tabentry \'$this_attr->{access_tabentry}\' is not valid."; @@ -502,18 +467,14 @@ sub getobjdefs my $lookup_table = $tabentry{'lookup_table'}; my $intabhash = 0; my $notsearched = 0; - foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) - { + foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) { # Check whether the attribute is already in %tabhash # The %tabhash is for performance considerations - if ( ($lookup_attr eq 'node') && ($objtype eq 'node') ){ + if ( ($lookup_attr eq 'node') && ($objtype eq 'node') ) { if (defined($tabhash{$lookup_table}{$objname}{$tabattr})) { - if ($verbose == 1) - { + if ($verbose == 1) { $objhash{$objname}{$attr} = "$tabhash{$lookup_table}{$objname}{$tabattr}\t(Table:$lookup_table - Key:$lookup_attr - Column:$tabattr)"; - } - else - { + } else { $objhash{$objname}{$attr} = $tabhash{$lookup_table}{$objname}{$tabattr}; } if (defined $chname_ref) { @@ -531,34 +492,25 @@ sub getobjdefs # Not in tabhash, # Need to lookup the table - if ($intabhash == 0 && $notsearched == 1) - { + if ($intabhash == 0 && $notsearched == 1) { # look up attr values my @rows = xCAT::DBobjUtils->getDBtable($lookup_table); - if (@rows) - { - foreach my $rowent (@rows) - { + if (@rows) { + foreach my $rowent (@rows) { my $match = 1; my $matchedattr; # Again, multiple keys support needs the "foreach" - foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) - { - if ($rowent->{$lookup_attr} ne $tabentry{'lookup_attrs'}{$lookup_attr}) - { + foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) { + if ($rowent->{$lookup_attr} ne $tabentry{'lookup_attrs'}{$lookup_attr}) { $match = 0; last; } } - if ($match == 1) - { - if ($verbose == 1) - { + if ($match == 1) { + if ($verbose == 1) { my @lookup_attrs = keys %{$tabentry{'lookup_attrs'}}; $objhash{$objname}{$attr} = "$rowent->{$tabattr}\t(Table:$lookup_table - Key: @lookup_attrs - Column:$tabattr)"; - } - else - { + } else { $objhash{$objname}{$attr} = $rowent->{$tabattr}; } if (defined $chname_ref) { @@ -607,20 +559,16 @@ sub getDBtable # save this table info - in case this subr gets called multiple times # --nocache flag specifies not to use cahe - if (grep(/^$table$/, @::foundTableList) && !$::opt_nc) - { + if (grep(/^$table$/, @::foundTableList) && !$::opt_nc) { # already have this @rows = @{$::TableHash{$table}}; - } - else - { + } else { # need to get info from DB my $thistable = xCAT::Table->new($table, -create => 1); - if (!$thistable) - { + if (!$thistable) { return undef; } @@ -639,12 +587,9 @@ sub getDBtable } # end if not cached - if (@rows) - { + if (@rows) { return @rows; - } - else - { + } else { return undef; } } @@ -693,8 +638,7 @@ sub setobjdefs my %DBhash; my @attrs; - foreach my $objname (keys %objhash) - { + foreach my $objname (keys %objhash) { my $type = $objhash{$objname}{objtype}; $DBhash{$objname} = $type; @attrs = keys %{$objhash{$objname}}; @@ -708,15 +652,13 @@ sub setobjdefs # - which table attrs correspond to which object attrs # - what the keys are for each table # update the tables a row at a time - foreach my $objname (keys %objhash) - { + foreach my $objname (keys %objhash) { # get attr=val that are set in the DB ?? my $type = $objhash{$objname}{objtype}; # handle the monitoring table as a special case !!!!! - if ($type eq 'monitoring') - { + if ($type eq 'monitoring') { # Get the names of the attrs stored in monitoring table # get the object type decription from Schema.pm @@ -725,15 +667,13 @@ sub setobjdefs # get a list of valid attr names # for this type object my @attrlist; - foreach my $entry (@{$datatype->{'attrs'}}) - { + foreach my $entry (@{$datatype->{'attrs'}}) { push(@attrlist, $entry->{'attr_name'}); } # open the tables (monitoring and monsetting) my $montable = xCAT::Table->new('monitoring', -create => 1, -autocommit => 0); - if (!$montable) - { + if (!$montable) { my $rsp; $rsp->{data}->[0] = "Could not set the \'$montable\' table."; xCAT::MsgUtils->message("E", $rsp, $::callback); @@ -741,8 +681,7 @@ sub setobjdefs } # open the table my $monsettable = xCAT::Table->new('monsetting', -create => 1, -autocommit => 0); - if (!$monsettable) - { + if (!$monsettable) { my $rsp; $rsp->{data}->[0] = "Could not set the \'$monsettable\' table."; xCAT::MsgUtils->message("E", $rsp, $::callback); @@ -752,33 +691,24 @@ sub setobjdefs my %keyhash; my %updates; - foreach my $attr (keys %{$objhash{$objname}}) - { + foreach my $attr (keys %{$objhash{$objname}}) { my $val; - if ($attr eq 'objtype') - { + if ($attr eq 'objtype') { next; } # determine the value if we have plus or minus - if ($::plus_option) - { + if ($::plus_option) { # add new to existing - at the end - comma separated - if (defined($DBattrvals{$objname}{$attr})) - { + if (defined($DBattrvals{$objname}{$attr})) { $val = "$DBattrvals{$objname}{$attr},$objhash{$objname}{$attr}"; - } - else - { + } else { $val = "$objhash{$objname}{$attr}"; } - } - elsif ($::minus_option) - { + } elsif ($::minus_option) { # remove the specified list of values from the current # attr values. - if ($DBattrvals{$objname}{$attr}) - { + if ($DBattrvals{$objname}{$attr}) { # get the list of attrs to remove my @currentList = split(/,/, $DBattrvals{$objname}{$attr}); my @minusList = split(/,/, $objhash{$objname}{$attr}); @@ -786,14 +716,11 @@ sub setobjdefs # make a new list without the one specified my $first = 1; my $newlist; - foreach my $i (@currentList) - { + foreach my $i (@currentList) { chomp $i; - if (!grep(/^$i$/, @minusList)) - { + if (!grep(/^$i$/, @minusList)) { # set new groups list for node - if (!$first) - { + if (!$first) { $newlist .= ","; } $newlist .= $i; @@ -802,9 +729,7 @@ sub setobjdefs } $val = $newlist; } - } - else - { + } else { #just set the attr to what was provided! - replace $val = $objhash{$objname}{$attr}; } @@ -829,23 +754,19 @@ sub setobjdefs } #if ($type eq 'monitoring') # handle the site table as a special case !!!!! - if ($type eq 'site') - { + if ($type eq 'site') { # open the table my $thistable = xCAT::Table->new('site', -create => 1, -autocommit => 0); - if (!$thistable) - { + if (!$thistable) { my $rsp; $rsp->{data}->[0] = "Could not set the \'$thistable\' table."; xCAT::MsgUtils->message("E", $rsp, $::callback); return 1; } - foreach my $attr (keys %{$objhash{$objname}}) - { - if ($attr eq 'objtype') - { + foreach my $attr (keys %{$objhash{$objname}}) { + if ($attr eq 'objtype') { next; } @@ -853,25 +774,18 @@ sub setobjdefs $keyhash{key} = $attr; my $val; - if ($::plus_option) - { + if ($::plus_option) { # add new to existing - at the end - comma separated - if (defined($DBattrvals{$objname}{$attr})) - { + if (defined($DBattrvals{$objname}{$attr})) { $val = "$DBattrvals{$objname}{$attr},$objhash{$objname}{$attr}"; - } - else - { + } else { $val = "$objhash{$objname}{$attr}"; } - } - elsif ($::minus_option) - { + } elsif ($::minus_option) { # remove the specified list of values from the current # attr values. - if ($DBattrvals{$objname}{$attr}) - { + if ($DBattrvals{$objname}{$attr}) { # get the list of attrs to remove my @currentList = split(/,/, $DBattrvals{$objname}{$attr}); my @minusList = split(/,/, $objhash{$objname}{$attr}); @@ -879,14 +793,11 @@ sub setobjdefs # make a new list without the one specified my $first = 1; my $newlist; - foreach my $i (@currentList) - { + foreach my $i (@currentList) { chomp $i; - if (!grep(/^$i$/, @minusList)) - { + if (!grep(/^$i$/, @minusList)) { # set new groups list for node - if (!$first) - { + if (!$first) { $newlist .= ","; } $newlist .= $i; @@ -895,9 +806,7 @@ sub setobjdefs } $val = $newlist; } - } - else - { + } else { #just set the attr to what was provided! - replace $val = $objhash{$objname}{$attr}; @@ -908,21 +817,19 @@ sub setobjdefs $thistable->delEntries(\%keyhash); } else { # change the attr - my %updates; - $updates{value} = $val; + my %updates; + $updates{value} = $val; - my ($rc, $str) = $thistable->setAttribs(\%keyhash, \%updates); - if (!defined($rc)) - { - if ($::verbose) - { - my $rsp; - $rsp->{data}->[0] = - "Could not set the \'$attr\' attribute of the \'$objname\' object in the xCAT database."; - $rsp->{data}->[1] = - "Error returned is \'$str->errstr\'."; - xCAT::MsgUtils->message("I", $rsp, $::callback); - } + my ($rc, $str) = $thistable->setAttribs(\%keyhash, \%updates); + if (!defined($rc)) { + if ($::verbose) { + my $rsp; + $rsp->{data}->[0] = + "Could not set the \'$attr\' attribute of the \'$objname\' object in the xCAT database."; + $rsp->{data}->[1] = + "Error returned is \'$str->errstr\'."; + xCAT::MsgUtils->message("I", $rsp, $::callback); + } $ret = 1; } } @@ -949,8 +856,7 @@ sub setobjdefs # get a list of valid attr names # for this type object my %attrlist; - foreach my $entry (@{$datatype->{'attrs'}}) - { + foreach my $entry (@{$datatype->{'attrs'}}) { #push(@{$attrlist{$type}}, $entry->{'attr_name'}); $attrlist{$type}{$entry->{'attr_name'}} = 1; } @@ -958,24 +864,19 @@ sub setobjdefs my @attrprovided=(); # check FINALATTRS to see if all the attrs are valid - foreach my $attr (keys %{$objhash{$objname}}) - { + foreach my $attr (keys %{$objhash{$objname}}) { - if ($attr eq $objkey) - { + if ($attr eq $objkey) { next; } - if ($attr eq "objtype") - { + if ($attr eq "objtype") { # objtype not stored in object definition next; } - if (!defined($attrlist{$type}{$attr})) - { - if ($::verbose) - { + if (!defined($attrlist{$type}{$attr})) { + if ($::verbose) { my $rsp; $rsp->{data}->[0] = "\'$attr\' is not a valid attribute for type \'$type\'."; @@ -995,23 +896,20 @@ sub setobjdefs my %checkedattrs; my $invalidattr; - foreach my $this_attr (@{$datatype->{'attrs'}}) - { + foreach my $this_attr (@{$datatype->{'attrs'}}) { my %keyhash; my %updates; my %tabentry; my ($lookup_table, $lookup_attr, $lookup_data); my $attr_name = $this_attr->{attr_name}; - if ($attr_name eq $objkey) - { + if ($attr_name eq $objkey) { next; } # if we have a value for this attribute then process it # - otherwise go to the next attr - if (defined($objhash{$objname}{$attr_name})) - { + if (defined($objhash{$objname}{$attr_name})) { # check the defspec to see where this attr goes # the table for this attr might depend on the @@ -1020,8 +918,7 @@ sub setobjdefs # other attr value matches what we have # ex. like if I want to set hdwctrlpoint I will have # to match the right value for mgtmethod - if (exists($this_attr->{only_if})) - { + if (exists($this_attr->{only_if})) { my ($check_attr, $check_value) = split('\=', $this_attr->{only_if}); @@ -1062,8 +959,7 @@ sub setobjdefs next; } - if ( !($objhash{$objname}{$check_attr} =~ /\b$check_value\b/) && !($DBattrvals{$objname}{$check_attr} =~ /\b$check_value\b/) ) - { + if ( !($objhash{$objname}{$check_attr} =~ /\b$check_value\b/) && !($DBattrvals{$objname}{$check_attr} =~ /\b$check_value\b/) ) { if ( $invalidattr->{$attr_name}->{valid} ne 1 ) { $invalidattr->{$attr_name}->{valid} = 0; $invalidattr->{$attr_name}->{condition} = "\'$check_attr=$check_value\'"; @@ -1084,8 +980,7 @@ sub setobjdefs my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, $this_attr->{access_tabentry}, \%tabentry); - if ($rc != 0) - { + if ($rc != 0) { my $rsp; $rsp->{data}->[0] = "access_tabentry \'$this_attr->{access_tabentry}\' is not valid."; @@ -1095,69 +990,53 @@ sub setobjdefs $lookup_table = $tabentry{'lookup_table'}; # Set the lookup criteria for this attribute into %allupdates # the key is 'lookup_attrs' - foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) - { + foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) { $allupdates{$lookup_table}{$objname}{$attr_name}{'lookup_attrs'}{$lookup_attr} =$tabentry{'lookup_attrs'}{$lookup_attr}; } - } - else - { + } else { next; } my $val; my $delim = ','; - if(($type eq 'group') && ($DBattrvals{$objname}{'grouptype'} eq 'dynamic')) - { + if(($type eq 'group') && ($DBattrvals{$objname}{'grouptype'} eq 'dynamic')) { # dynamic node group selection string use "::" as delimiter $delim = '::'; } - if ($::plus_option) - { + if ($::plus_option) { # add new to existing - at the end - comma separated - if (defined($DBattrvals{$objname}{$attr_name})) - { + if (defined($DBattrvals{$objname}{$attr_name})) { # add the attr into the list if it's not already in the list! # and avoid the duplicate values my @DBattrarray = split(/$delim/, $DBattrvals{$objname}{$attr_name}); my @objhasharray = split(/$delim/, $objhash{$objname}{$attr_name}); - foreach my $objattr (@objhasharray) - { - if (!grep(/^\Q$objattr\E$/, @DBattrarray)) - { + foreach my $objattr (@objhasharray) { + if (!grep(/^\Q$objattr\E$/, @DBattrarray)) { push @DBattrarray, $objattr; } } $val = join($delim, @DBattrarray); - } - else - { + } else { $val = "$objhash{$objname}{$attr_name}"; } - } - elsif ($::minus_option) - { + } elsif ($::minus_option) { # remove the specified list of values from the current # attr values. - if ($DBattrvals{$objname}{$attr_name}) - { + if ($DBattrvals{$objname}{$attr_name}) { # get the list of attrs to remove my @currentList = split(/$delim/, $DBattrvals{$objname}{$attr_name}); my @minusList = split(/$delim/, $objhash{$objname}{$attr_name}); - foreach my $em (@minusList) - { - if (!(grep {$_ eq $em} @currentList)) - { - if (($::opt_t eq 'group') && ($DBattrvals{$objname}{'grouptype'} ne 'dynamic')) - { + foreach my $em (@minusList) { + if (!(grep {$_ eq $em} @currentList)) { + if (($::opt_t eq 'group') && ($DBattrvals{$objname}{'grouptype'} ne 'dynamic')) { my $rsp; $rsp->{data}->[0] = "$objname is not a member of \'$em\'."; xCAT::MsgUtils->message("W", $rsp, $::callback); @@ -1171,15 +1050,12 @@ sub setobjdefs # make a new list without the one specified my $first = 1; my $newlist; - foreach my $i (@currentList) - { + foreach my $i (@currentList) { chomp $i; - if (!grep(/^\Q$i\E$/, @minusList)) - { + if (!grep(/^\Q$i\E$/, @minusList)) { # set new list for node - if (!$first) - { + if (!$first) { $newlist .= "$delim"; } $newlist .= $i; @@ -1189,9 +1065,7 @@ sub setobjdefs $val = $newlist; } - } - else - { + } else { #just set the attr to what was provided! - replace $val = $objhash{$objname}{$attr_name}; @@ -1224,11 +1098,9 @@ my $tt = $invalidattr->{$att}->{valid}; # my @errlist; - foreach $a (@attrprovided) - { + foreach $a (@attrprovided) { # is this attr was not set then add it to the error list - if (!grep(/^$a$/, @setattrlist)) - { + if (!grep(/^$a$/, @setattrlist)) { push(@errlist, $a); $ret = 2; } @@ -1312,12 +1184,9 @@ my $tt = $invalidattr->{$att}->{valid}; my $xcatdefaultsps; my $xcatdefaultspbs; my @TableRowArray = xCAT::DBobjUtils->getDBtable('postscripts'); - if (@TableRowArray) - { - foreach my $tablerow (@TableRowArray) - { - if(($tablerow->{node} eq 'xcatdefaults') && !($tablerow->{disable})) - { + if (@TableRowArray) { + foreach my $tablerow (@TableRowArray) { + if(($tablerow->{node} eq 'xcatdefaults') && !($tablerow->{disable})) { $xcatdefaultsps = $tablerow->{postscripts}; $xcatdefaultspbs = $tablerow->{postbootscripts}; last; @@ -1471,19 +1340,16 @@ sub rmobjdefs # get the attr=vals for these objects so we know how to # find what tables have to be modified - foreach my $objname (sort (keys %typehash)) - { + foreach my $objname (sort (keys %typehash)) { my $type = $typehash{$objname}; # special handling for site table - if ($type eq 'site') - { + if ($type eq 'site') { my %DBattrvals = xCAT::DBobjUtils->getobjdefs(\%typehash); my $thistable = xCAT::Table->new('site', -create => 1, -autocommit => 0); my %keyhash; - foreach my $attr (keys %{$DBattrvals{$objname}}) - { + foreach my $attr (keys %{$DBattrvals{$objname}}) { # ex. key = attr $keyhash{key} = $attr; @@ -1501,8 +1367,7 @@ sub rmobjdefs # go through the list of valid attrs # - need to delete the row with a $key value of $objname from $table # - make a hash containing $delhash{$table}{$key}= $objname - foreach my $this_attr (@{$datatype->{'attrs'}}) - { + foreach my $this_attr (@{$datatype->{'attrs'}}) { my $attr = $this_attr->{attr_name}; # get table lookup info from Schema.pm @@ -1510,8 +1375,7 @@ sub rmobjdefs # the subroutine parse_access_tabentry is used for supporting multiple keys my %tabentry = (); my $rc = xCAT::DBobjUtils->parse_access_tabentry($objname, $this_attr->{access_tabentry}, \%tabentry); - if ($rc != 0) - { + if ($rc != 0) { my $rsp; $rsp->{data}->[0] = "access_tabentry \'$this_attr->{access_tabentry}\' is not valid."; @@ -1526,8 +1390,7 @@ sub rmobjdefs my $attr_name = $this_attr->{'attr_name'}; # we'll need table name, object name, attribute name and the lookup entries # put this info in a hash - we'll process it later - below - foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) - { + foreach my $lookup_attr (keys %{$tabentry{'lookup_attrs'}}) { $tablehash{$lookup_table}{$objname}{$attr_name}{$lookup_attr} = $tabentry{'lookup_attrs'}{$lookup_attr}; } @@ -1583,8 +1446,7 @@ sub rmobjdefs #... ##=========================================================# # now for each table - clear the entry - foreach my $table (keys %tablehash) - { + foreach my $table (keys %tablehash) { my @all_keyhash; my $thistable = @@ -1592,18 +1454,14 @@ sub rmobjdefs foreach my $obj (keys %{$tablehash{$table}}) { my %keyhash; - foreach my $attr (keys %{$tablehash{$table}{$obj}}) - { - foreach my $key (keys %{$tablehash{$table}{$obj}{$attr}}) - { + foreach my $attr (keys %{$tablehash{$table}{$obj}}) { + foreach my $key (keys %{$tablehash{$table}{$obj}{$attr}}) { #multiple keys support - if (defined($keyhash{$key}) && ($keyhash{$key} ne $tablehash{$table}{$obj}{$attr}{$key})) - { + if (defined($keyhash{$key}) && ($keyhash{$key} ne $tablehash{$table}{$obj}{$attr}{$key})) { my %tmpkeyhash; # copy hash - foreach my $hashkey (keys %keyhash) - { + foreach my $hashkey (keys %keyhash) { $tmpkeyhash{$hashkey} = $keyhash{$hashkey}; } push @all_keyhash, \%tmpkeyhash; @@ -1668,15 +1526,13 @@ sub readFileInput my $look_for_colon = 1; # start with first line that has a colon my $objtype; - foreach my $l (@lines) - { + foreach my $l (@lines) { # skip blank and comment lines next if ($l =~ /^\s*$/ || $l =~ /^\s*#/); # see if it's a stanza name - if (grep(/:\s*$/, $l)) - { + if (grep(/:\s*$/, $l)) { $look_for_colon = 0; # ok - we have a colon @@ -1690,8 +1546,7 @@ sub readFileInput ($objectname, $junk2) = ($1, $2); # if $junk2 is defined or there's an = - if ($junk2 || grep(/=/, $objectname)) - { + if ($junk2 || grep(/=/, $objectname)) { # error - invalid header $line in node definition file # skipping to next node stanza @@ -1705,13 +1560,11 @@ sub readFileInput # could have different default stanzas for different object types - if ($objectname =~ /default/) - { + if ($objectname =~ /default/) { ($junk1, $objtype) = split(/-/, $objectname); - if ($objtype) - { + if ($objtype) { $objectname = 'default'; } @@ -1720,9 +1573,7 @@ sub readFileInput push(@::fileobjnames, $objectname); - } - elsif (($l =~ /^\s*(.*?)\s*=\s*(.*)\s*/) && (!$look_for_colon)) - { + } elsif (($l =~ /^\s*(.*?)\s*=\s*(.*)\s*/) && (!$look_for_colon)) { my $attr = $1; my $val = $2; $attr =~ s/^\s*//; # Remove any leading whitespace @@ -1734,15 +1585,12 @@ sub readFileInput $val =~ s/^\s*"\s*//; $val =~ s/\s*"\s*$//; - if ($objectname eq "default") - { + if ($objectname eq "default") { # set the default for this attribute $::defAttrs{$objtype}{$attr} = $val; - } - else - { + } else { # set the value in the hash for this object $::FILEATTRS{$objectname}{$attr} = $val; @@ -1752,13 +1600,11 @@ sub readFileInput # the objtype should be the first etntry in each stanza # so after we set the defaults they will be overwritten # by any values that appear in the rest of the stanza - if ($attr eq 'objtype') - { + if ($attr eq 'objtype') { push(@::fileobjtypes, $val); # $val will be the object type ex. site, node etc. - foreach my $a (keys %{$::defAttrs{$val}}) - { + foreach my $a (keys %{$::defAttrs{$val}}) { # set the default values for this object hash $::FILEATTRS{$objectname}{$a} = $::defAttrs{$val}{$a}; @@ -1766,9 +1612,7 @@ sub readFileInput } } - } - else - { + } else { # error - invalid line in node definition file $look_for_colon++; @@ -1822,28 +1666,23 @@ sub getGroupMembers $objhash{$objectname}{'grouptype'} = 'static'; } - if ($objhash{$objectname}{'grouptype'} eq 'static') - { + if ($objhash{$objectname}{'grouptype'} eq 'static') { my $table = "nodelist"; my @TableRowArray = xCAT::DBobjUtils->getDBtable($table); my $first = 1; - foreach (@TableRowArray) - { + foreach (@TableRowArray) { # if find the group name in the "groups" attr value then add the # node name to the member list #if ($_->{'groups'} =~ /$objectname/) my @nodeGroupList = split(',', $_->{'groups'}); - if (grep(/^$objectname$/, @nodeGroupList)) - - { + if (grep(/^$objectname$/, @nodeGroupList)) { chomp($_->{'node'}); - if (!$first) - { + if (!$first) { $members .= ","; } $members .= $_->{'node'}; @@ -1851,9 +1690,7 @@ sub getGroupMembers } } - } - elsif ($objhash{$objectname}{'grouptype'} eq 'dynamic') - { + } elsif ($objhash{$objectname}{'grouptype'} eq 'dynamic') { # find all nodes that satisfy the criteria specified in "wherevals" # value @@ -1866,8 +1703,7 @@ sub getGroupMembers my @tmpWhereList = split('::', $objhash{$objectname}{'wherevals'}); my $rc = xCAT::Utils->parse_selection_string(\@tmpWhereList, \%whereHash); - if ($rc != 0) - { + if ($rc != 0) { my $rsp; $rsp->{data}->[0] = "The \'-w\' option has an incorrect attr*val pair."; @@ -1880,8 +1716,7 @@ sub getGroupMembers # create a hash of obj names and types my %tmphash; - foreach my $n (@tmplist) - { + foreach my $n (@tmplist) { $tmphash{$n} = 'node'; } @@ -1891,18 +1726,14 @@ sub getGroupMembers # The attribute 'node' can be used as a key of selection string, # however, the 'node' attribute is not included in the getobjdefs hash - foreach my $objname (keys %nodeattrhash) - { + foreach my $objname (keys %nodeattrhash) { $nodeattrhash{$objname}{'node'} = $objname; } my $first = 1; - foreach my $objname (keys %nodeattrhash) - { - if (xCAT::Utils->selection_string_match(\%nodeattrhash, $objname, \%whereHash)) - { + foreach my $objname (keys %nodeattrhash) { + if (xCAT::Utils->selection_string_match(\%nodeattrhash, $objname, \%whereHash)) { chomp($objname); - if (!$first) - { + if (!$first) { $members .= ","; } $members .= $objname; @@ -1952,20 +1783,17 @@ sub getNetwkInfo # read the networks table my @TableRowArray = xCAT::DBobjUtils->getDBtable('networks'); - if (! @TableRowArray) - { + if (! @TableRowArray) { return undef; } # for each node - get the network info - foreach my $node (@nodelist) - { + foreach my $node (@nodelist) { # get, check, split the node IP my $IP = xCAT::NetworkUtils->getipaddr($node); chomp $IP; - unless (($IP =~ /\d+\.\d+\.\d+\.\d+/) || ($IP =~ /:/)) - { + unless (($IP =~ /\d+\.\d+\.\d+\.\d+/) || ($IP =~ /:/)) { next; } my ($ia, $ib, $ic, $id) = split('\.', $IP); @@ -1979,29 +1807,23 @@ sub getNetwkInfo chomp $NM; chomp $net; - if(xCAT::NetworkUtils->ishostinsubnet($IP, $NM, $net)) - { + if(xCAT::NetworkUtils->ishostinsubnet($IP, $NM, $net)) { # fill in the hash - foreach my $attr (@attrnames) { if ( defined($_->{$attr}) ) { $nethash{$node}{$attr} = $_->{$attr}; } } - if($nethash{$node}{'gateway'} eq '') - { - if(xCAT::NetworkUtils->ip_forwarding_enabled()) - { + if($nethash{$node}{'gateway'} eq '') { + if(xCAT::NetworkUtils->ip_forwarding_enabled()) { $nethash{$node}{'gateway'} = xCAT::NetworkUtils->my_ip_in_subnet($net, $NM); - } - else - { + } else { $nethash{$node}{'gateway'} = ''; } $nethash{$node}{'myselfgw'} = 1; # For hwctrl commands, it is possible that this subroutine is called # on MN instead of SN, if the hcp SN is not set - if (xCAT::Utils->isMN() && !$nethash{$node}{'gateway'}) - { + if (xCAT::Utils->isMN() && !$nethash{$node}{'gateway'}) { # does not have ip address in this subnet, # use the node attribute 'xcatmaster' or site.master my @nodes = ("$node"); @@ -2068,8 +1890,7 @@ sub parse_access_tabentry() my ($class, $objname, $access_tabentry, $tabentry_ref) = @_; # ex. 'nodelist.node', 'attr:node' - foreach my $ent (split('::', $access_tabentry)) - { + foreach my $ent (split('::', $access_tabentry)) { # ex. 'nodelist.node', 'attr:node' my ($lookup_key, $lookup_value) = split('\=', $ent); @@ -2079,16 +1900,14 @@ sub parse_access_tabentry() # ex. 'attr', 'node' my ($lookup_type, $lookup_data) = split('\:', $lookup_value); - if (!defined($tabentry_ref->{'lookup_table'})) - { + if (!defined($tabentry_ref->{'lookup_table'})) { $tabentry_ref->{'lookup_table'} = $lookup_table; } # Only support one lookup table in the access_tabentry # Do we need to support multiple tables in one access_tabentry ???? # has not seen any requirement... - if ($lookup_table ne $tabentry_ref->{'lookup_table'}) - { + if ($lookup_table ne $tabentry_ref->{'lookup_table'}) { my $rsp; $rsp->{data}->[0] = "The access_tabentry \"$access_tabentry\" is not valid, can not specify more than one tables to look up."; @@ -2096,8 +1915,7 @@ sub parse_access_tabentry() return 1; } - if ($lookup_type eq 'attr') - { + if ($lookup_type eq 'attr') { # TODO: may need to update in the future # for now, the "val" in attr:val in # Schema.pm can only be the object name @@ -2105,13 +1923,9 @@ sub parse_access_tabentry() # be caution about the performance # looking up table is time consuming $tabentry_ref->{'lookup_attrs'}->{$lookup_attr} = $objname; - } - elsif ($lookup_type eq 'str') - { + } elsif ($lookup_type eq 'str') { $tabentry_ref->{'lookup_attrs'}->{$lookup_attr} = $lookup_data; - } - else - { + } else { my $rsp; $rsp->{data}->[0] = "The access_tabentry \"$access_tabentry\" is not valid, the lookup type can only be 'attr' or 'str'."; @@ -2149,8 +1963,7 @@ my %PPCHASH; sub getchildren { my $parent = shift; - if (($parent) && ($parent =~ /xCAT::/)) - { + if (($parent) && ($parent =~ /xCAT::/)) { $parent = shift; } $::RUNCMD_RC = 0; @@ -2175,18 +1988,15 @@ sub getchildren if ( $t eq 'fsp' or $t eq 'bpa') { # build hash of ppc.parent -> ppc.node push @{$PPCHASH{$p}}, $c; - } - elsif ($t eq 'blade') { + } elsif ($t eq 'blade') { push @{$PPCHASH{$c}}, $entry->{hcp}; } } else { # go look in the nodetype table to find nodetype my $type = getnodetype($c, "ppc"); - if ( $type eq 'fsp' or $type eq 'bpa') - { + if ( $type eq 'fsp' or $type eq 'bpa') { # build hash of ppc.parent -> ppc.node push @{$PPCHASH{$p}}, $c; - } - elsif ($type eq "blade") { + } elsif ($type eq "blade") { push @{$PPCHASH{$c}}, $entry->{hcp}; } } @@ -2204,8 +2014,7 @@ sub getchildren } } # if port not input - if ( !defined($port )) - { + if ( !defined($port )) { return \@children; } else { if (@children) { @@ -2216,15 +2025,12 @@ sub getchildren return undef; } my $sides = $vpdtab->getNodesAttribs(\@children, ['side']); - if(!$sides) - { + if(!$sides) { return undef; } - foreach my $n (@children) - { + foreach my $n (@children) { my $nside = $sides->{$n}->[0]; - if ($nside->{side} =~ /$port/) - { + if ($nside->{side} =~ /$port/) { push @children_port, $n; } } @@ -2264,8 +2070,7 @@ my %NODETYPEHASH; sub getnodetype { my $nodes = shift; - if (($nodes) && ($nodes =~ /xCAT::/)) - { + if (($nodes) && ($nodes =~ /xCAT::/)) { $nodes = shift; } my $table = shift; @@ -2504,8 +2309,7 @@ my %PARENT_CHILDREN_CEC; sub getcecchildren { my $parent = shift; - if (($parent) && ($parent =~ /xCAT::/)) - { + if (($parent) && ($parent =~ /xCAT::/)) { $parent = shift; } my @children = (); @@ -2516,8 +2320,7 @@ sub getcecchildren $::RUNCMD_RC = 1; return undef; } - if ($ppctab) - { + if ($ppctab) { my @ps = $ppctab->getAllNodeAttribs(['node','parent','nodetype']); foreach my $entry ( @ps ) { my $p = $entry->{parent}; @@ -2575,8 +2378,7 @@ sub getcecchildren sub judge_node { my $node = shift; - if (($node) && ($node =~ /xCAT::/)) - { + if (($node) && ($node =~ /xCAT::/)) { $node = shift; } my $type = shift; @@ -2592,21 +2394,17 @@ sub judge_node } if ($type =~ /^fsp$/) { - if ($parenttype =~ /^cec$/) - { + if ($parenttype =~ /^cec$/) { $flag = 1; - } else - { + } else { $flag = 0; } } if ($type =~ /^bpa$/) { - if ($parenttype =~ /^frame$/) - { + if ($parenttype =~ /^frame$/) { $flag = 1; - } else - { + } else { $flag = 0; } } @@ -2645,8 +2443,7 @@ sub judge_node sub expandnicsattr() { my $nicstr = shift; - if (($nicstr) && ($nicstr =~ /xCAT::/)) - { + if (($nicstr) && ($nicstr =~ /xCAT::/)) { $nicstr = shift; } my $nicnames = shift; @@ -2665,30 +2462,25 @@ sub expandnicsattr() # $nicarr[1]: eth1!3.1.1.1|4.1.1.1 my @nicarr = split(/,/, $nicval); - foreach my $nicentry (@nicarr) - { + foreach my $nicentry (@nicarr) { #nicentry: eth0!1.1.1.1|2.1.1.1 # $nicv[0]: eth0 # $nicv[1]: 1.1.1.1|2.1.1.1 my @nicv = split(/!/, $nicentry); # only return nic* attr for these specific nics - if ($nicnames) - { + if ($nicnames) { my @nics = split(/,/, $nicnames); - if ($nicv[0]) - { + if ($nicv[0]) { # Do not need to return the nic attr for this nic - if (!grep(/^$nicv[0]$/, @nics)) - { + if (!grep(/^$nicv[0]$/, @nics)) { next; } } } # ignore the line that does not have nicname or value - if ($nicv[0] && $nicv[1]) - { + if ($nicv[0] && $nicv[1]) { $ret .= " $nicattr.$nicv[0]=$nicv[1]\n"; } } @@ -2735,26 +2527,21 @@ sub expandnicsattr() sub collapsenicsattr() { my $nodeattrhash = shift; - if (($nodeattrhash) && ($nodeattrhash =~ /xCAT::/)) - { + if (($nodeattrhash) && ($nodeattrhash =~ /xCAT::/)) { $nodeattrhash = shift; } my $objname = shift; my %nicattrs = (); - foreach my $nodeattr (keys %{$nodeattrhash}) - { + foreach my $nodeattr (keys %{$nodeattrhash}) { # e.g nicips.eth0 # do not need to handle nic attributes without the postfix .ethx, # it will be overwritten by the attributes with the postfix .ethx, - if ($nodeattr =~ /^(nic\w+)\.(.*)$/) - { - if ($1 && $2) - { + if ($nodeattr =~ /^(nic\w+)\.(.*)$/) { + if ($1 && $2) { # chdef nicips.eth2= to remove the definition for eth2 # in this case, the $nodeattrhash->{'nicips.eth0'} is blank - if ($nodeattrhash->{$nodeattr}) - { + if ($nodeattrhash->{$nodeattr}) { # $nicattrs{nicips}{eth0} = "1.1.1.1|1.2.1.1" $nicattrs{$1}{$2} = $nodeattrhash->{$nodeattr}; } @@ -2766,11 +2553,9 @@ sub collapsenicsattr() } # $nicattrs{'nicips'}{'eth0'} = "1.1.1.1|1.2.1.1" # $nicattrs{'nicips'}{'eth1'} = "2.1.1.1|2.2.1.1" - foreach my $nicattr (keys %nicattrs) - { + foreach my $nicattr (keys %nicattrs) { my @tmparray = (); - foreach my $nicname (keys %{$nicattrs{$nicattr}}) - { + foreach my $nicname (keys %{$nicattrs{$nicattr}}) { # eth0!1.1.1.1|1.2.1.1 push @tmparray, "$nicname!$nicattrs{$nicattr}{$nicname}"; }