From e786262c56bafd448899c6fa11f6a831a7af6fb3 Mon Sep 17 00:00:00 2001 From: lissav Date: Thu, 13 Sep 2012 12:01:48 +0000 Subject: [PATCH] add getTablesNodeAttribs XML support git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13782 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/tabutils.pm | 104 ++++++++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 6685310cd..fb6cf82f1 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -59,6 +59,7 @@ sub handled_commands getAllEntries => "tabutils", getNodesAttribs => "tabutils", getTablesAllNodeAttribs => "tabutils", + getTablesNodeAttribs => "tabutils", setNodesAttribs => "tabutils", delEntries => "tabutils", getAttribs => "tabutils", @@ -162,6 +163,10 @@ sub process_request { return getTablesAllNodeAttribs($request,$callback); } + elsif ($command eq "getTablesNodeAttribs") + { + return getTablesNodeAttribs($request,$callback); + } elsif ($command eq "setNodesAttribs") { return setNodesAttribs($request,$callback); @@ -2375,7 +2380,9 @@ sub getNodesAttribs my %datseg=(); $datseg{name} = [$node]; foreach my $key (keys %$rec) { + if ($key ne "node") { # do not put in the added node attribute $datseg{$key} = [$rec->{$key}]; + } } push @{$noderecs{$node}}, \%datseg; } @@ -2388,7 +2395,7 @@ sub getNodesAttribs return; } # getTablesAllNodeAttribs -# Read all all the nodes from the input tables and get the input attribute +# Read all the nodes from the input tables and get the input attributes # or get ALL attributes, if the word ALL is used. # If the ALL is input then read all the attributes # @@ -2453,7 +2460,7 @@ sub getTablesAllNodeAttribs push @attrs, $c; } } - # read all the nodes and there attributes in this table + # read all the nodes and their attributes in this table my @nodeentries = $tab->getAllNodeAttribs(\@attrs); foreach my $node (@nodeentries){ # build the node entrys @@ -2475,6 +2482,99 @@ sub getTablesAllNodeAttribs return; } +# getTablesNodeAttribs +# Read the nodes in the noderange from the input tables +# and get the input attributes +# or get ALL attributes, if the word ALL is used. +# If the ALL is input then read all the attributes +# +#PCM +#getTablesAllNodeAttribs +#blade01-blade10 +# +#nodelist +#groups +#status +#
+# +#nodetype +#ALL +#
+# . +# . +# . +#
+# +# +# +#tablename1 +# +#n1 +#value1 +#value1 +#. +#valueN +# +#
+# . +# . +# . +#
+# +sub getTablesNodeAttribs +{ + my $request = shift; + my $cb = shift; + my $command = $request->{command}->[0]; + my %rsp; + + # process each table in the request + my $tables = $request->{table}; + my $node = $request->{node}; + my @nodes=@$node; + foreach my $tabhash (@$tables) { + + my $tablename = $tabhash->{tablename}->[0]; + my $attr = $tabhash->{attr}; + my @attrs=@$attr; + my $tab=xCAT::Table->new($tablename); + my %noderecs; + my $recs; + # build the table name record + @{$noderecs{table}->[0]->{tablename}} = $tablename; + # if request for ALL attributes + if (grep (/ALL/,@attrs)) { # read the schema and build array of all attrs + @attrs=(); + my $schema = xCAT::Table->getTableSchema($tablename); + my $desc = $schema->{descriptions}; + foreach my $c (@{$schema->{cols}}) { + # my $space = (length($c)<7 ? "\t\t" : "\t"); + push @attrs, $c; + } + } + # read the nodes and their attributes in this table + my $rechash = $tab->getNodesAttribs(\@nodes,\@attrs); + foreach my $node (@nodes){ + my $recs = $rechash->{$node}; + foreach my $rec (@$recs) { + my %datseg=(); + $datseg{name} = [$node]; + foreach my $key (keys %$rec) { + if ($key ne "node") { # do not put in the added node attribute + $datseg{$key} = [$rec->{$key}]; + } + } + push @{$noderecs{table}->[0]->{node}}, \%datseg; + } + + } + push @{$rsp{"table"}}, @{$noderecs{table}}; + } # end of all table processing +# for checkin XML created +#my $xmlrec=XMLout(\%rsp,RootName=>'xcatresponse',NoAttr=>1,KeyAttr=>[]); + $cb->(\%rsp); + return; +} # # setNodesAttribs - setNodesAttribs # Sets Nodes attributes for noderange for each of the tables supplied