From 285c79265f3ce838bc7ec4587ef773381f9c6a99 Mon Sep 17 00:00:00 2001 From: lissav Date: Mon, 23 Apr 2012 10:50:35 +0000 Subject: [PATCH] moving DButils.pm function into tabutils to make use of database access code already implemented git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@12300 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/DButils.pm | 171 ------------------------ 1 file changed, 171 deletions(-) delete mode 100644 xCAT-server/lib/xcat/plugins/DButils.pm diff --git a/xCAT-server/lib/xcat/plugins/DButils.pm b/xCAT-server/lib/xcat/plugins/DButils.pm deleted file mode 100644 index 282232f23..000000000 --- a/xCAT-server/lib/xcat/plugins/DButils.pm +++ /dev/null @@ -1,171 +0,0 @@ -# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html -##################################################### -# -# xCAT plugin package to handle various commands that work with the -# xCAT tables for an XML interface -# -##################################################### -package xCAT_plugin::DButils; -use strict; -use warnings; -use xCAT::Table; -use xCAT::Schema; -use Data::Dumper; -use xCAT::NodeRange qw/noderange abbreviate_noderange/; -use xCAT::Schema; -use xCAT::Utils; -use XML::Simple; #smaller than libxml.... -$XML::Simple::PREFERRED_PARSER='XML::Parser'; -use Getopt::Long; -1; - -#some quick aliases to table/value -my %shortnames = ( - groups => [qw(nodelist groups)], - tags => [qw(nodelist groups)], - mgt => [qw(nodehm mgt)], - #switch => [qw(switch switch)], - ); - -##################################################### -# Return list of commands handled by this plugin -##################################################### -sub handled_commands -{ - return { - getAllEntries => "DButils", - getNodesAttribs => "DButils" - }; -} - - -##################################################### -# Process the command -##################################################### -sub process_request -{ - my $request = shift; - my $callback = shift; - my $command = $request->{command}->[0]; - if ($command eq "getAllEntries") - { - return getAllEntries($request,$callback); - } - elsif ($command eq "getNodesAttribs") - { - return getNodesAttribs($request,$callback); - } - else - { - print "$command not implemented yet\n"; - return (1, "$command not written yet"); - } - -} -# -# Read all the rows from the input table name and returns the response, so -# that the XML will look like this -# -# -#value1 -#. -#. -#. -#valueN -# -#. -#. -#. -# -# -# -sub getAllEntries -{ - my $request = shift; - my $cb = shift; - my $command = $request->{command}->[0]; - my $tablename = $request->{table}->[0]; - my $tab=xCAT::Table->new($tablename); - my %rsp; - my $recs = $tab->getAllEntries("all"); - unless (@$recs) # table exists, but is empty. Show header. - { - if (defined($xCAT::Schema::tabspec{$tablename})) - { - my $header = "#"; - my @array =@{$xCAT::Schema::tabspec{$tablename}->{cols}}; - foreach my $arow (@array) { - $header .= $arow; - $header .= ","; - } - chop $header; - push @{$rsp{row}}, $header; - $cb->(\%rsp); - return; - } - } - my %noderecs; - foreach my $rec (@$recs) { - my %datseg=(); - foreach my $key (keys %$rec) { - #$datseg{$key} = [$rec->{$key}]; - $datseg{$key} = $rec->{$key}; - } - push @{$noderecs{"row"}}, \%datseg; - } - push @{$rsp{"row"}}, @{$noderecs{"row"}}; -# for checkin XML created -#my $xmlrec=XMLout(\%rsp,RootName=>'xcatresponse',NoAttr=>1,KeyAttr=>[]); - $cb->(\%rsp); - - return; -} -# Read all the array of attributes for the noderange from the input table. -# -# -# nodename -#value1 -#. -#. -#. -#valueN -# -#. -#. -#. -# -# -# -sub getNodesAttribs -{ - my $request = shift; - my $cb = shift; - my $node = $request->{node}; - my $command = $request->{command}->[0]; - my $tablename = $request->{table}->[0]; - my $attr = $request->{attr}; - my $tab=xCAT::Table->new($tablename); - my @nodes = @$node; - my @attrs= @$attr; - my %rsp; - my %noderecs; - my $rechash = $tab->getNodesAttribs(\@nodes,\@attrs); - foreach my $node (@nodes){ - my %datseg=(); - $datseg{name} = [$node]; - my $recs = $rechash->{$node}; - foreach my $rec (@$recs) { - foreach my $key (keys %$rec) { - $datseg{$key} = [$rec->{$key}]; - } - push @{$noderecs{$node}}, \%datseg; - } - push @{$rsp{"node"}}, @{$noderecs{$node}}; - - } -# for checkin XML created -#my $xmlrec=XMLout(\%rsp,RootName=>'xcatresponse',NoAttr=>1,KeyAttr=>[]); - $cb->(\%rsp); - return; -} -