2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#####################################################
|
|
|
|
#
|
2008-02-06 15:21:54 +00:00
|
|
|
# xCAT plugin package to handle various commands that work with the
|
2007-10-26 22:44:33 +00:00
|
|
|
# xCAT tables
|
2012-09-20 15:26:03 +00:00
|
|
|
#
|
2007-10-26 22:44:33 +00:00
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
package xCAT_plugin::tabutils;
|
2008-07-18 19:37:43 +00:00
|
|
|
use strict;
|
2008-07-18 22:36:32 +00:00
|
|
|
use warnings;
|
2007-10-26 22:44:33 +00:00
|
|
|
use xCAT::Table;
|
|
|
|
use xCAT::Schema;
|
|
|
|
use Data::Dumper;
|
2009-04-15 16:45:48 +00:00
|
|
|
use xCAT::NodeRange qw/noderange abbreviate_noderange/;
|
2008-02-14 14:25:49 +00:00
|
|
|
use xCAT::Schema;
|
2008-07-07 18:29:55 +00:00
|
|
|
use xCAT::Utils;
|
2012-09-12 13:45:34 +00:00
|
|
|
#use XML::Simple;
|
2012-08-09 04:07:40 +00:00
|
|
|
use xCAT::TableUtils;
|
2011-03-25 09:42:56 +00:00
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use xCAT::DBobjUtils;
|
2008-03-08 14:14:00 +00:00
|
|
|
use Getopt::Long;
|
2009-09-15 18:37:18 +00:00
|
|
|
my $requestcommand;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
1;
|
|
|
|
|
|
|
|
#some quick aliases to table/value
|
|
|
|
my %shortnames = (
|
2008-02-06 15:21:54 +00:00
|
|
|
groups => [qw(nodelist groups)],
|
|
|
|
tags => [qw(nodelist groups)],
|
|
|
|
mgt => [qw(nodehm mgt)],
|
2008-05-19 18:04:04 +00:00
|
|
|
#switch => [qw(switch switch)],
|
2008-02-06 15:21:54 +00:00
|
|
|
);
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
#####################################################
|
|
|
|
# Return list of commands handled by this plugin
|
|
|
|
#####################################################
|
2008-02-06 15:21:54 +00:00
|
|
|
sub handled_commands
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
gettab => "tabutils",
|
|
|
|
tabdump => "tabutils",
|
2010-10-27 15:27:04 +00:00
|
|
|
lsxcatd => "tabutils",
|
2010-03-31 14:07:19 +00:00
|
|
|
tabprune => "tabutils",
|
2008-02-06 15:21:54 +00:00
|
|
|
tabrestore => "tabutils",
|
2011-09-07 15:20:00 +00:00
|
|
|
tabch => "tabutils",
|
2009-09-29 20:41:13 +00:00
|
|
|
nodegrpch => "tabutils",
|
2008-02-06 15:21:54 +00:00
|
|
|
nodech => "tabutils",
|
|
|
|
nodeadd => "tabutils",
|
|
|
|
noderm => "tabutils",
|
2008-02-14 14:25:49 +00:00
|
|
|
tabls => "tabutils", # not implemented yet
|
2008-02-06 15:21:54 +00:00
|
|
|
nodels => "tabutils",
|
2008-02-14 14:25:49 +00:00
|
|
|
getnodecfg => "tabutils", # not implemented yet (?? this doesn't seem much different from gettab)
|
|
|
|
addattr => "tabutils", # not implemented yet
|
|
|
|
delattr => "tabutils", # not implemented yet
|
|
|
|
chtype => "tabutils", # not implemented yet
|
|
|
|
nr => "tabutils", # not implemented yet
|
2009-04-14 18:27:43 +00:00
|
|
|
rnoderange => "tabutils", # not implemented yet
|
2010-01-05 05:12:38 +00:00
|
|
|
tabgrep => "tabutils",
|
2012-05-13 11:44:38 +00:00
|
|
|
getAllEntries => "tabutils",
|
|
|
|
getNodesAttribs => "tabutils",
|
2012-09-12 13:45:34 +00:00
|
|
|
getTablesAllNodeAttribs => "tabutils",
|
2012-09-13 18:24:34 +00:00
|
|
|
getTablesNodesAttribs => "tabutils",
|
2012-09-14 13:25:54 +00:00
|
|
|
getTablesAllRowAttribs => "tabutils",
|
2012-09-11 11:33:45 +00:00
|
|
|
setNodesAttribs => "tabutils",
|
2012-05-13 11:44:38 +00:00
|
|
|
delEntries => "tabutils",
|
2012-05-14 19:28:17 +00:00
|
|
|
getAttribs => "tabutils",
|
2012-05-16 17:34:18 +00:00
|
|
|
setAttribs => "tabutils",
|
2012-05-20 18:12:21 +00:00
|
|
|
NodeRange => "tabutils",
|
2011-03-20 06:53:44 +00:00
|
|
|
gennr => "tabutils"
|
2008-02-06 15:21:54 +00:00
|
|
|
};
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
2008-03-08 14:14:00 +00:00
|
|
|
# Each cmd now returns its own usage inside its function
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
#####################################################
|
|
|
|
# Process the command
|
|
|
|
#####################################################
|
2008-02-06 15:21:54 +00:00
|
|
|
sub process_request
|
|
|
|
{
|
2008-03-08 14:14:00 +00:00
|
|
|
#use Getopt::Long;
|
2008-02-06 15:21:54 +00:00
|
|
|
Getopt::Long::Configure("bundling");
|
2008-03-08 14:14:00 +00:00
|
|
|
#Getopt::Long::Configure("pass_through");
|
|
|
|
Getopt::Long::Configure("no_pass_through");
|
2008-02-06 15:21:54 +00:00
|
|
|
|
|
|
|
my $request = shift;
|
|
|
|
my $callback = shift;
|
2009-09-15 18:37:18 +00:00
|
|
|
$requestcommand = shift;
|
2008-02-06 15:21:54 +00:00
|
|
|
my $nodes = $request->{node};
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my $args = $request->{arg};
|
2008-03-08 14:14:00 +00:00
|
|
|
#unless ($args or $nodes or $request->{data})
|
|
|
|
#{
|
|
|
|
#if ($usage{$command})
|
|
|
|
#{
|
|
|
|
#$callback->({data => [$usage{$command}]});
|
|
|
|
#return;
|
|
|
|
#}
|
|
|
|
#}
|
2008-02-06 15:21:54 +00:00
|
|
|
|
|
|
|
if ($command eq "nodels")
|
|
|
|
{
|
2008-03-05 16:31:35 +00:00
|
|
|
return nodels($nodes, $args, $callback, $request->{emptynoderange}->[0]);
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
2009-04-14 18:27:43 +00:00
|
|
|
elsif ($command eq "rnoderange")
|
|
|
|
{
|
|
|
|
return rnoderange($nodes,$args,$callback);
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
elsif ($command eq "noderm" or $command eq "rmnode")
|
|
|
|
{
|
|
|
|
return noderm($nodes, $args, $callback);
|
|
|
|
}
|
|
|
|
elsif ($command eq "nodeadd" or $command eq "addnode")
|
|
|
|
{
|
2008-02-14 14:25:49 +00:00
|
|
|
return nodech($nodes, $args, $callback, 1);
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
2009-09-29 20:41:13 +00:00
|
|
|
elsif ($command eq "nodegrpch" or $command eq "chnodegrp")
|
|
|
|
{
|
|
|
|
return nodech($nodes, $args, $callback, "groupch");
|
|
|
|
}
|
2011-03-20 06:53:44 +00:00
|
|
|
elsif ($command eq "gennr")
|
|
|
|
{
|
|
|
|
return gennr($nodes, $args, $callback);
|
|
|
|
}
|
2009-09-29 20:41:13 +00:00
|
|
|
elsif ($command eq "nodech" or $command eq "chnode")
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
2008-02-14 14:25:49 +00:00
|
|
|
return nodech($nodes, $args, $callback, 0);
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
elsif ($command eq "tabrestore")
|
|
|
|
{
|
|
|
|
return tabrestore($request, $callback);
|
|
|
|
}
|
|
|
|
elsif ($command eq "tabdump")
|
|
|
|
{
|
2012-06-07 18:16:29 +00:00
|
|
|
return tabdump($args, $callback,$request);
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
2010-10-27 15:27:04 +00:00
|
|
|
elsif ($command eq "lsxcatd")
|
|
|
|
{
|
|
|
|
return lsxcatd($args, $callback);
|
|
|
|
}
|
2010-03-31 14:07:19 +00:00
|
|
|
elsif ($command eq "tabprune")
|
|
|
|
{
|
|
|
|
return tabprune($args, $callback);
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
elsif ($command eq "gettab")
|
|
|
|
{
|
|
|
|
return gettab($request, $callback);
|
|
|
|
}
|
|
|
|
elsif ($command eq "tabgrep")
|
|
|
|
{
|
|
|
|
return tabgrep($nodes, $callback);
|
|
|
|
}
|
2010-02-03 22:06:43 +00:00
|
|
|
elsif ($command eq "tabch"){
|
2011-09-07 15:20:00 +00:00
|
|
|
return tabch($request, $callback);
|
2010-02-03 22:06:43 +00:00
|
|
|
}
|
2012-04-23 12:32:58 +00:00
|
|
|
elsif ($command eq "getAllEntries")
|
|
|
|
{
|
|
|
|
return getAllEntries($request,$callback);
|
|
|
|
}
|
|
|
|
elsif ($command eq "getNodesAttribs")
|
|
|
|
{
|
|
|
|
return getNodesAttribs($request,$callback);
|
|
|
|
}
|
2012-09-12 13:45:34 +00:00
|
|
|
elsif ($command eq "getTablesAllNodeAttribs")
|
|
|
|
{
|
|
|
|
return getTablesAllNodeAttribs($request,$callback);
|
|
|
|
}
|
2012-09-13 18:24:34 +00:00
|
|
|
elsif ($command eq "getTablesNodesAttribs")
|
2012-09-13 12:01:48 +00:00
|
|
|
{
|
2012-09-13 18:24:34 +00:00
|
|
|
return getTablesNodesAttribs($request,$callback);
|
2012-09-13 12:01:48 +00:00
|
|
|
}
|
2012-09-14 13:25:54 +00:00
|
|
|
elsif ($command eq "getTablesAllRowAttribs")
|
|
|
|
{
|
|
|
|
return getTablesAllRowAttribs($request,$callback);
|
|
|
|
}
|
2012-09-11 11:33:45 +00:00
|
|
|
elsif ($command eq "setNodesAttribs")
|
2012-04-26 15:19:21 +00:00
|
|
|
{
|
2012-09-11 11:33:45 +00:00
|
|
|
return setNodesAttribs($request,$callback);
|
2012-04-26 15:19:21 +00:00
|
|
|
}
|
2012-05-13 11:44:38 +00:00
|
|
|
elsif ($command eq "delEntries")
|
|
|
|
{
|
|
|
|
return delEntries($request,$callback);
|
|
|
|
}
|
2012-05-14 19:28:17 +00:00
|
|
|
elsif ($command eq "getAttribs")
|
|
|
|
{
|
|
|
|
return getAttribs($request,$callback);
|
|
|
|
}
|
2012-05-16 17:34:18 +00:00
|
|
|
elsif ($command eq "setAttribs")
|
|
|
|
{
|
|
|
|
return setAttribs($request,$callback);
|
|
|
|
}
|
2012-05-20 18:12:21 +00:00
|
|
|
elsif ($command eq "NodeRange")
|
|
|
|
{
|
|
|
|
return NodeRange($request,$callback);
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
print "$command not implemented yet\n";
|
|
|
|
return (1, "$command not written yet");
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-03-05 16:49:19 +00:00
|
|
|
# Display particular attributes, using query strings.
|
2008-02-14 14:25:49 +00:00
|
|
|
sub gettab
|
|
|
|
{
|
|
|
|
my $req = shift;
|
|
|
|
my $callback = shift;
|
2008-03-05 16:49:19 +00:00
|
|
|
my $HELP;
|
2008-05-19 17:59:56 +00:00
|
|
|
my $NOTERSE;
|
2008-03-05 16:49:19 +00:00
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
my $gettab_usage = sub {
|
2011-03-20 06:53:44 +00:00
|
|
|
my $exitcode = shift @_;
|
2008-03-05 16:49:19 +00:00
|
|
|
my %rsp;
|
2008-05-19 17:59:56 +00:00
|
|
|
push @{$rsp{data}}, "Usage: gettab [-H|--with-fieldname] key=value,... table.attribute ...";
|
2008-03-05 16:49:19 +00:00
|
|
|
push @{$rsp{data}}, " gettab [-?|-h|--help]";
|
|
|
|
if ($exitcode) { $rsp{errorcode} = $exitcode; }
|
|
|
|
$callback->(\%rsp);
|
2008-07-18 22:36:32 +00:00
|
|
|
};
|
2008-03-05 16:49:19 +00:00
|
|
|
|
2011-03-20 06:53:44 +00:00
|
|
|
# Process arguments
|
|
|
|
if (!defined($req->{arg})) { $gettab_usage->(1); return; }
|
2008-03-05 16:49:19 +00:00
|
|
|
@ARGV = @{$req->{arg}};
|
2008-07-18 22:36:32 +00:00
|
|
|
if (!GetOptions('h|?|help' => \$HELP,'H|with-fieldname' => \$NOTERSE)) { $gettab_usage->(1); return; }
|
2008-03-05 16:49:19 +00:00
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
if ($HELP) { $gettab_usage->(0); return; }
|
|
|
|
if (scalar(@ARGV)<2) { $gettab_usage->(1); return; }
|
2008-03-05 16:49:19 +00:00
|
|
|
|
|
|
|
# Get all the key/value pairs into a hash
|
|
|
|
my $keyspec = shift @ARGV;
|
2008-02-14 14:25:49 +00:00
|
|
|
my @keypairs = split /,/, $keyspec;
|
|
|
|
my %keyhash;
|
|
|
|
foreach (@keypairs)
|
|
|
|
{
|
|
|
|
(my $key, my $value) = split /=/, $_;
|
2008-05-16 18:47:32 +00:00
|
|
|
unless (defined $key) {
|
2008-07-18 22:36:32 +00:00
|
|
|
$gettab_usage->(1);
|
2008-05-16 18:47:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-02-14 14:25:49 +00:00
|
|
|
$keyhash{$key} = $value;
|
|
|
|
}
|
2008-03-05 16:49:19 +00:00
|
|
|
|
|
|
|
# Group the columns asked for by table (so we can do 1 query per table)
|
2008-02-14 14:25:49 +00:00
|
|
|
my %tabhash;
|
2008-05-16 21:14:09 +00:00
|
|
|
my $terse = 2;
|
2008-05-19 17:59:56 +00:00
|
|
|
if ($NOTERSE) {
|
|
|
|
$terse = 0;
|
|
|
|
}
|
2008-03-05 16:49:19 +00:00
|
|
|
foreach my $tabvalue (@ARGV)
|
2008-02-14 14:25:49 +00:00
|
|
|
{
|
2008-05-16 21:14:09 +00:00
|
|
|
$terse--;
|
2008-02-14 14:25:49 +00:00
|
|
|
(my $table, my $column) = split /\./, $tabvalue;
|
|
|
|
$tabhash{$table}->{$column} = 1;
|
|
|
|
}
|
2008-03-05 16:49:19 +00:00
|
|
|
|
2008-05-16 18:47:32 +00:00
|
|
|
#Sanity check the key against all tables in question
|
|
|
|
foreach my $tabn (keys %tabhash) {
|
|
|
|
foreach my $kcheck (keys %keyhash) {
|
|
|
|
unless (grep /^$kcheck$/, @{$xCAT::Schema::tabspec{$tabn}->{cols}}) {
|
|
|
|
$callback->({error => ["Unkown key $kcheck to $tabn"],errorcode=>[1]});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-05 16:49:19 +00:00
|
|
|
# Get the requested columns from each table
|
2008-02-14 14:25:49 +00:00
|
|
|
foreach my $tabn (keys %tabhash)
|
|
|
|
{
|
|
|
|
my $tab = xCAT::Table->new($tabn);
|
|
|
|
(my $ent) = $tab->getAttribs(\%keyhash, keys %{$tabhash{$tabn}});
|
2012-08-30 17:14:21 +00:00
|
|
|
if ($ent) {
|
|
|
|
foreach my $coln (keys %{$tabhash{$tabn}})
|
|
|
|
{
|
2008-05-19 17:59:56 +00:00
|
|
|
if ($terse > 0) {
|
2008-05-16 21:14:09 +00:00
|
|
|
$callback->({data => ["" . $ent->{$coln}]});
|
|
|
|
} else {
|
|
|
|
$callback->({data => ["$tabn.$coln: " . $ent->{$coln}]});
|
|
|
|
}
|
2012-08-30 17:14:21 +00:00
|
|
|
}
|
2008-02-14 14:25:49 +00:00
|
|
|
}
|
|
|
|
$tab->close;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
sub noderm
|
|
|
|
{
|
|
|
|
my $nodes = shift;
|
|
|
|
my $args = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $VERSION;
|
|
|
|
my $HELP;
|
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
my $noderm_usage = sub {
|
2011-03-20 06:53:44 +00:00
|
|
|
my $exitcode = shift @_;
|
2008-02-06 15:21:54 +00:00
|
|
|
my %rsp;
|
2008-03-08 14:14:00 +00:00
|
|
|
push @{$rsp{data}}, "Usage:";
|
|
|
|
push @{$rsp{data}}, " noderm noderange";
|
|
|
|
push @{$rsp{data}}, " noderm {-v|--version}";
|
|
|
|
push @{$rsp{data}}, " noderm [-?|-h|--help]";
|
|
|
|
if ($exitcode) { $rsp{errorcode} = $exitcode; }
|
|
|
|
$cb->(\%rsp);
|
2008-07-18 22:36:32 +00:00
|
|
|
};
|
2008-02-06 15:21:54 +00:00
|
|
|
|
2008-08-08 17:20:32 +00:00
|
|
|
if ($args) {
|
|
|
|
@ARGV = @{$args};
|
2009-10-30 11:36:23 +00:00
|
|
|
} else {
|
|
|
|
@ARGV = ();
|
2008-08-08 17:20:32 +00:00
|
|
|
}
|
2008-07-18 22:36:32 +00:00
|
|
|
if (!GetOptions('h|?|help' => \$HELP, 'v|version' => \$VERSION) ) { $noderm_usage->(1); return; }
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
if ($HELP) { $noderm_usage->(0); return; }
|
2008-02-06 15:21:54 +00:00
|
|
|
|
2008-03-08 14:14:00 +00:00
|
|
|
if ($VERSION) {
|
2008-02-06 15:21:54 +00:00
|
|
|
my %rsp;
|
2008-07-07 18:29:55 +00:00
|
|
|
my $version = xCAT::Utils->Version();
|
2008-07-18 19:37:43 +00:00
|
|
|
$rsp{data}->[0] = "$version";
|
|
|
|
$cb->(\%rsp);
|
2008-02-06 15:21:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-03-08 14:14:00 +00:00
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
if (!$nodes) { $noderm_usage->(1); return; }
|
2012-05-23 06:02:23 +00:00
|
|
|
#my $sitetab = xCAT::Table->new('site');
|
|
|
|
#my $pdhcp = $sitetab->getAttribs({key=>'pruneservices'},['value']);
|
2012-08-09 04:07:40 +00:00
|
|
|
my @entries = xCAT::TableUtils->get_site_attribute("pruneservices");
|
2012-05-23 06:02:23 +00:00
|
|
|
my $t_entry = $entries[0];
|
|
|
|
if ( defined($t_entry) and $t_entry !~ /n(\z|o)/i) {
|
2009-09-15 19:11:39 +00:00
|
|
|
$requestcommand->({command=>['makedhcp'],node=>$nodes,arg=>['-d']});
|
2009-09-15 18:37:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-08 14:14:00 +00:00
|
|
|
|
|
|
|
# Build the argument list for using the -d option of nodech to do our work for us
|
2008-02-06 15:21:54 +00:00
|
|
|
my @tablist = ("-d");
|
|
|
|
foreach (keys %{xCAT::Schema::tabspec})
|
|
|
|
{
|
|
|
|
if (grep /^node$/, @{$xCAT::Schema::tabspec{$_}->{cols}})
|
|
|
|
{
|
|
|
|
push @tablist, $_;
|
|
|
|
}
|
|
|
|
}
|
2011-03-25 09:42:56 +00:00
|
|
|
if (scalar(@$nodes)) {
|
|
|
|
for my $nn ( @$nodes ) {
|
|
|
|
my $nt = xCAT::DBobjUtils->getnodetype($nn);
|
2011-06-20 13:40:59 +00:00
|
|
|
if ( $nt and $nt =~ /^(cec|frame)$/ ) {
|
2011-03-25 09:42:56 +00:00
|
|
|
my $cnodep = xCAT::DBobjUtils->getchildren($nn);
|
|
|
|
if ($cnodep) {
|
|
|
|
my $cnode = join ',', @$cnodep;
|
2011-05-12 03:00:44 +00:00
|
|
|
if ($cnode)
|
|
|
|
{
|
|
|
|
my $rsp;
|
|
|
|
$rsp->{data}->[0] =
|
|
|
|
"Removed a $nt node, please remove these nodes belongs to it manually: $cnode \n";
|
|
|
|
xCAT::MsgUtils->message("I", $rsp, $cb);
|
|
|
|
}
|
2011-03-25 09:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
nodech($nodes, \@tablist, $cb, 0);
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2013-09-13 17:58:52 +00:00
|
|
|
#
|
|
|
|
# restores the table from the input CSV file. Default deletes the table rows and
|
|
|
|
# replaces with the rows in the file
|
|
|
|
# If -a flag is input then it adds the rows from the CSV file to the table.
|
|
|
|
#
|
2008-02-06 15:21:54 +00:00
|
|
|
sub tabrestore
|
|
|
|
{
|
2008-02-14 14:25:49 +00:00
|
|
|
# the usage for tabrestore is in the tabrestore client cmd
|
2008-02-06 15:21:54 +00:00
|
|
|
|
|
|
|
#request->{data} is an array of CSV formatted lines
|
|
|
|
my $request = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $table = $request->{table}->[0];
|
2013-09-13 17:58:52 +00:00
|
|
|
my $addrows = $request->{addrows}->[0];
|
2011-05-12 12:44:10 +00:00
|
|
|
# do not allow teal tables
|
|
|
|
if ( $table =~ /^x_teal/ ) {
|
|
|
|
$cb->({error => "$table is not supported in tabrestore. Use Teal maintenance commands. ",errorcode=>1});
|
|
|
|
return 1;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
my $tab = xCAT::Table->new($table, -create => 1, -autocommit => 0);
|
2008-02-14 14:25:49 +00:00
|
|
|
unless ($tab) {
|
|
|
|
$cb->({error => "Unable to open $table",errorcode=>4});
|
2008-02-06 15:21:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-09-13 17:58:52 +00:00
|
|
|
if (!defined($addrows)) { # this is a replace not add rows
|
|
|
|
$tab->delEntries(); #Yes, delete *all* entries
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
my $header = shift @{$request->{data}};
|
2009-01-14 14:41:38 +00:00
|
|
|
unless ($header =~ /^#/) {
|
|
|
|
$cb->({error => "Data missing header line starting with #",errorcode=>1});
|
|
|
|
return;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
$header =~ s/"//g; #Strip " from overzealous CSV apps
|
|
|
|
$header =~ s/^#//;
|
|
|
|
$header =~ s/\s+$//;
|
|
|
|
my @colns = split(/,/, $header);
|
2009-09-16 15:38:40 +00:00
|
|
|
my $tcol;
|
|
|
|
foreach $tcol (@colns) { #validate the restore data has no invalid column names
|
|
|
|
unless (grep /^$tcol\z/,@{$xCAT::Schema::tabspec{$table}->{cols}}) {
|
|
|
|
$cb->({error => "The header line indicates that column '$tcol' should exist, which is not defined in the schema for '$table'",errorcode=>1});
|
|
|
|
return;
|
|
|
|
}
|
2009-09-28 17:14:07 +00:00
|
|
|
#print Dumper(grep /^$tcol\z/,@{$xCAT::Schema::tabspec{$table}->{cols}});
|
2009-09-16 15:38:40 +00:00
|
|
|
}
|
2009-09-28 17:14:07 +00:00
|
|
|
#print "We passed it!\n";
|
2008-02-06 15:21:54 +00:00
|
|
|
my $line;
|
|
|
|
my $rollback = 0;
|
2009-02-04 01:53:34 +00:00
|
|
|
|
|
|
|
my @tmp=$tab->getAutoIncrementColumns(); #get the columns that are auto increment by DB.
|
|
|
|
my %auto_cols=();
|
|
|
|
foreach (@tmp) { $auto_cols{$_}=1;}
|
|
|
|
|
Changed the parsing in tabedit to allow newlines in the column fields within double quotes
Tested with:
#node,rack,u,chassis,slot,room,comments,disable
"
rr
a004a",,"42",,,,"te
st",
"rra
004b",,,,,,"test2",
"rra004c",,,,,,"test3",
"bca01","1","2",,,,,"ssdf
sdfsd
sdfs
sdf
d
dfdf""
sdf
"
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5237 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2010-02-19 16:06:06 +00:00
|
|
|
|
|
|
|
my $linenumber;
|
|
|
|
my $linecount = scalar(@{$request->{data}});
|
|
|
|
|
|
|
|
LINE: for($linenumber = 0; $linenumber < $linecount; $linenumber++)
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
Changed the parsing in tabedit to allow newlines in the column fields within double quotes
Tested with:
#node,rack,u,chassis,slot,room,comments,disable
"
rr
a004a",,"42",,,,"te
st",
"rra
004b",,,,,,"test2",
"rra004c",,,,,,"test3",
"bca01","1","2",,,,,"ssdf
sdfsd
sdfs
sdf
d
dfdf""
sdf
"
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5237 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2010-02-19 16:06:06 +00:00
|
|
|
$line = @{$request->{data}}[$linenumber];
|
2008-02-06 15:21:54 +00:00
|
|
|
$line =~ s/\s+$//;
|
|
|
|
my $origline = $line; #save for error reporting
|
|
|
|
my %record;
|
|
|
|
my $col;
|
|
|
|
foreach $col (@colns)
|
|
|
|
{
|
|
|
|
if ($line =~ /^,/ or $line eq "")
|
|
|
|
{ #Match empty, or end of line that is empty
|
|
|
|
#TODO: should we detect when there weren't enough CSV fields on a line to match colums?
|
2009-02-04 01:53:34 +00:00
|
|
|
if (!exists($auto_cols{$col})) {
|
2011-03-20 06:53:44 +00:00
|
|
|
$record{$col} = undef;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
$line =~ s/^,//;
|
|
|
|
}
|
|
|
|
elsif ($line =~ /^[^,]*"/)
|
|
|
|
{ # We have stuff in quotes... pain...
|
|
|
|
#I don't know what I'm doing, so I'll do it a hard way....
|
|
|
|
if ($line !~ /^"/)
|
|
|
|
{
|
|
|
|
$rollback = 1;
|
|
|
|
$cb->(
|
|
|
|
{
|
|
|
|
error =>
|
|
|
|
"CSV missing opening \" for record with \" characters on line $linenumber, character "
|
2008-02-14 14:25:49 +00:00
|
|
|
. index($origline, $line) . ": $origline", errorcode=>4
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
next LINE;
|
|
|
|
}
|
|
|
|
my $offset = 1;
|
|
|
|
my $nextchar;
|
|
|
|
my $ent;
|
|
|
|
while (not defined $ent)
|
|
|
|
{
|
|
|
|
$offset = index($line, '"', $offset);
|
|
|
|
$offset++;
|
Changed the parsing in tabedit to allow newlines in the column fields within double quotes
Tested with:
#node,rack,u,chassis,slot,room,comments,disable
"
rr
a004a",,"42",,,,"te
st",
"rra
004b",,,,,,"test2",
"rra004c",,,,,,"test3",
"bca01","1","2",,,,,"ssdf
sdfsd
sdfs
sdf
d
dfdf""
sdf
"
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5237 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2010-02-19 16:06:06 +00:00
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
if ($offset <= 0)
|
Changed the parsing in tabedit to allow newlines in the column fields within double quotes
Tested with:
#node,rack,u,chassis,slot,room,comments,disable
"
rr
a004a",,"42",,,,"te
st",
"rra
004b",,,,,,"test2",
"rra004c",,,,,,"test3",
"bca01","1","2",,,,,"ssdf
sdfsd
sdfs
sdf
d
dfdf""
sdf
"
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5237 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2010-02-19 16:06:06 +00:00
|
|
|
{ #the matching quote is not on this line of the file
|
2008-02-06 15:21:54 +00:00
|
|
|
|
Changed the parsing in tabedit to allow newlines in the column fields within double quotes
Tested with:
#node,rack,u,chassis,slot,room,comments,disable
"
rr
a004a",,"42",,,,"te
st",
"rra
004b",,,,,,"test2",
"rra004c",,,,,,"test3",
"bca01","1","2",,,,,"ssdf
sdfsd
sdfs
sdf
d
dfdf""
sdf
"
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5237 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2010-02-19 16:06:06 +00:00
|
|
|
if($linenumber < $linecount)
|
|
|
|
{ #it's not the end of the world, we have more lines to check
|
|
|
|
|
|
|
|
my $continuedline = @{$request->{data}}[++$linenumber];
|
|
|
|
$offset = length($line);
|
|
|
|
$line .= "\n" . $continuedline;
|
|
|
|
$line =~ s/\s+$//;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ #the matching quote was not found before the end of the file
|
|
|
|
|
|
|
|
#MALFORMED CSV, request rollback, report an error
|
|
|
|
$rollback = 1;
|
|
|
|
$cb->(
|
|
|
|
{
|
|
|
|
error =>
|
|
|
|
"CSV unmatched \" in record on line $linenumber, character "
|
|
|
|
. index($origline, $line) . ": $origline", errorcode=>4
|
|
|
|
}
|
|
|
|
);
|
|
|
|
next LINE;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
else
|
Changed the parsing in tabedit to allow newlines in the column fields within double quotes
Tested with:
#node,rack,u,chassis,slot,room,comments,disable
"
rr
a004a",,"42",,,,"te
st",
"rra
004b",,,,,,"test2",
"rra004c",,,,,,"test3",
"bca01","1","2",,,,,"ssdf
sdfsd
sdfs
sdf
d
dfdf""
sdf
"
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5237 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2010-02-19 16:06:06 +00:00
|
|
|
{ #the next quote was on the current line
|
|
|
|
|
|
|
|
$nextchar = substr($line, $offset, 1);
|
|
|
|
|
|
|
|
if ($nextchar eq '"')
|
|
|
|
{ #the case of 2 double quotes. ignore them and move on
|
|
|
|
$offset++;
|
|
|
|
}
|
|
|
|
elsif ($offset eq length($line) or $nextchar eq ',')
|
|
|
|
{ #hit the end of the line or at least the end of the column
|
|
|
|
$ent = substr($line, 0, $offset, '');
|
|
|
|
$line =~ s/^,//;
|
|
|
|
chop $ent;
|
|
|
|
$ent = substr($ent, 1);
|
|
|
|
$ent =~ s/""/"/g;
|
2011-03-20 06:53:44 +00:00
|
|
|
if (!exists($auto_cols{$col}))
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
$record{$col} = $ent;
|
|
|
|
}
|
Changed the parsing in tabedit to allow newlines in the column fields within double quotes
Tested with:
#node,rack,u,chassis,slot,room,comments,disable
"
rr
a004a",,"42",,,,"te
st",
"rra
004b",,,,,,"test2",
"rra004c",,,,,,"test3",
"bca01","1","2",,,,,"ssdf
sdfsd
sdfs
sdf
d
dfdf""
sdf
"
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5237 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2010-02-19 16:06:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cb->(
|
|
|
|
{
|
|
|
|
error =>
|
|
|
|
"CSV unescaped \" in record on line $linenumber, character "
|
|
|
|
. index($origline, $line) . ": $origline", errorcode=>4
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$rollback = 1;
|
|
|
|
next LINE;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elsif ($line =~ /^([^,]+)/)
|
|
|
|
{ #easiest case, no Text::Balanced needed..
|
2011-03-20 06:53:44 +00:00
|
|
|
if (!exists($auto_cols{$col}))
|
Changed the parsing in tabedit to allow newlines in the column fields within double quotes
Tested with:
#node,rack,u,chassis,slot,room,comments,disable
"
rr
a004a",,"42",,,,"te
st",
"rra
004b",,,,,,"test2",
"rra004c",,,,,,"test3",
"bca01","1","2",,,,,"ssdf
sdfsd
sdfs
sdf
d
dfdf""
sdf
"
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5237 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
2010-02-19 16:06:06 +00:00
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
$record{$col} = $1;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
$line =~ s/^([^,]+)(,|$)//;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
if ($line)
|
|
|
|
{
|
|
|
|
$rollback = 1;
|
2008-02-14 14:25:49 +00:00
|
|
|
$cb->({error => "Too many fields on line $linenumber: $origline | $line", errorcode=>4});
|
2007-10-26 22:44:33 +00:00
|
|
|
next LINE;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
|
2013-09-19 17:04:40 +00:00
|
|
|
#check for error from DB and rollback
|
2008-02-06 15:21:54 +00:00
|
|
|
my @rc = $tab->setAttribs(\%record, \%record);
|
|
|
|
if (not defined($rc[0]))
|
|
|
|
{
|
|
|
|
$rollback = 1;
|
2008-02-14 14:25:49 +00:00
|
|
|
$cb->({error => "DB error " . $rc[1] . " with line $linenumber: " . $origline, errorcode=>4});
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($rollback)
|
|
|
|
{
|
|
|
|
$tab->rollback();
|
|
|
|
$tab->close;
|
|
|
|
undef $tab;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tab->commit; #Made it all the way here, commit
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
|
2008-03-05 16:49:19 +00:00
|
|
|
# Display a list of tables, or a specific table in CSV format
|
2008-02-06 15:21:54 +00:00
|
|
|
sub tabdump
|
|
|
|
{
|
|
|
|
my $args = shift;
|
|
|
|
my $cb = shift;
|
2012-06-07 18:16:29 +00:00
|
|
|
my $request = shift;
|
2008-02-06 15:21:54 +00:00
|
|
|
my $table = "";
|
2008-02-14 14:25:49 +00:00
|
|
|
my $HELP;
|
2008-02-21 21:10:35 +00:00
|
|
|
my $DESC;
|
2011-03-29 19:29:17 +00:00
|
|
|
my $OPTW;
|
|
|
|
my $VERSION;
|
2011-05-11 17:49:18 +00:00
|
|
|
my $FILENAME;
|
2013-08-01 16:07:30 +00:00
|
|
|
my $NUMBERENTRIES;
|
2008-02-14 14:25:49 +00:00
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
my $tabdump_usage = sub {
|
2011-03-20 06:53:44 +00:00
|
|
|
my $exitcode = shift @_;
|
2008-02-14 14:25:49 +00:00
|
|
|
my %rsp;
|
2008-02-21 21:10:35 +00:00
|
|
|
push @{$rsp{data}}, "Usage: tabdump [-d] [table]";
|
2011-03-29 19:29:17 +00:00
|
|
|
push @{$rsp{data}}, " tabdump [table]";
|
2011-05-11 17:49:18 +00:00
|
|
|
push @{$rsp{data}}, " tabdump [-f <filename>] [table]";
|
2013-08-01 16:07:30 +00:00
|
|
|
push @{$rsp{data}}, " tabdump [-n <# of records>] [auditlog | eventlog]";
|
2011-03-29 19:29:17 +00:00
|
|
|
push @{$rsp{data}}, " tabdump [-w attr==val [-w attr=~val] ...] [table]";
|
2011-05-11 17:49:18 +00:00
|
|
|
push @{$rsp{data}}, " tabdump [-w attr==val [-w attr=~val] ...] [-f <filename>] [table]";
|
2008-02-14 14:25:49 +00:00
|
|
|
push @{$rsp{data}}, " tabdump [-?|-h|--help]";
|
2011-03-29 19:29:17 +00:00
|
|
|
push @{$rsp{data}}, " tabdump {-v|--version}";
|
|
|
|
push @{$rsp{data}}, " tabdump ";
|
2008-02-14 14:25:49 +00:00
|
|
|
if ($exitcode) { $rsp{errorcode} = $exitcode; }
|
|
|
|
$cb->(\%rsp);
|
2008-07-18 22:36:32 +00:00
|
|
|
};
|
2008-02-14 14:25:49 +00:00
|
|
|
|
2011-03-20 06:53:44 +00:00
|
|
|
# Process arguments
|
2008-07-31 18:19:11 +00:00
|
|
|
if ($args) {
|
|
|
|
@ARGV = @{$args};
|
|
|
|
}
|
2013-08-06 16:15:26 +00:00
|
|
|
Getopt::Long::Configure("posix_default");
|
|
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
|
2011-03-29 19:29:17 +00:00
|
|
|
|
|
|
|
if (!GetOptions(
|
|
|
|
'h|?|help' => \$HELP,
|
|
|
|
'v|version' => \$VERSION,
|
2013-08-01 16:07:30 +00:00
|
|
|
'n|lines=i' => \$NUMBERENTRIES,
|
2011-03-29 19:29:17 +00:00
|
|
|
'd' => \$DESC,
|
2011-05-11 17:49:18 +00:00
|
|
|
'f=s' => \$FILENAME,
|
2011-03-29 19:29:17 +00:00
|
|
|
'w=s@' => \$OPTW,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{$tabdump_usage->(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($VERSION) {
|
|
|
|
my %rsp;
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
$rsp{data}->[0] = "$version";
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-07 18:16:29 +00:00
|
|
|
if ($FILENAME and $FILENAME !~ /^\//) { $FILENAME =~ s/^/$request->{cwd}->[0]\//; }
|
2013-08-06 16:15:26 +00:00
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
if ($HELP) { $tabdump_usage->(0); return; }
|
2013-08-06 16:15:26 +00:00
|
|
|
|
2013-08-01 16:07:30 +00:00
|
|
|
if (($NUMBERENTRIES) && ($DESC)) {
|
|
|
|
$cb->({error => "You cannot use the -n and -d flag together. ",errorcode=>1});
|
|
|
|
return 1;
|
|
|
|
}
|
2013-08-06 16:15:26 +00:00
|
|
|
|
2013-08-01 16:07:30 +00:00
|
|
|
if (($NUMBERENTRIES) && ($OPTW)) {
|
|
|
|
$cb->({error => "You cannot use the -n and -w flag together. ",errorcode=>1});
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (($NUMBERENTRIES) && ($FILENAME)) {
|
|
|
|
$cb->({error => "You cannot use the -n and -f flag together. ",errorcode=>1});
|
|
|
|
return 1;
|
|
|
|
}
|
2008-07-18 22:36:32 +00:00
|
|
|
if (scalar(@ARGV)>1) { $tabdump_usage->(1); return; }
|
2008-02-14 14:25:49 +00:00
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
my %rsp;
|
2008-02-14 14:25:49 +00:00
|
|
|
# If no arguments given, we display a list of the tables
|
|
|
|
if (!scalar(@ARGV)) {
|
2011-05-11 17:49:18 +00:00
|
|
|
# if -f filename give but no table name, display error
|
|
|
|
if ($FILENAME) {
|
|
|
|
$cb->({error => "table name missing from the command input. ",errorcode=>1});
|
|
|
|
return 1;
|
|
|
|
}
|
2011-03-20 06:53:44 +00:00
|
|
|
if ($DESC) { # display the description of each table
|
|
|
|
my $tab = xCAT::Table->getDescriptions();
|
|
|
|
foreach my $key (keys %$tab) {
|
|
|
|
my $space = (length($key)<7 ? "\t\t" : "\t");
|
|
|
|
push @{$rsp{data}}, "$key:$space".$tab->{$key}."\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { push @{$rsp{data}}, xCAT::Table->getTableList(); } # if no descriptions, just display the list of table names
|
|
|
|
@{$rsp{data}} = sort @{$rsp{data}};
|
|
|
|
if ($DESC && scalar(@{$rsp{data}})) { chop($rsp{data}->[scalar(@{$rsp{data}})-1]); } # remove the final newline
|
2008-02-14 14:25:49 +00:00
|
|
|
$cb->(\%rsp);
|
2011-03-20 06:53:44 +00:00
|
|
|
return;
|
2008-02-14 14:25:49 +00:00
|
|
|
}
|
2011-03-29 19:29:17 +00:00
|
|
|
# get the table name
|
2008-02-14 14:25:49 +00:00
|
|
|
$table = $ARGV[0];
|
2013-08-06 16:15:26 +00:00
|
|
|
|
2013-08-01 16:07:30 +00:00
|
|
|
# if -n can only be the auditlog or eventlog
|
|
|
|
if ($NUMBERENTRIES) {
|
|
|
|
if (!( $table =~ /^auditlog/ ) && (!($table =~ /^eventlog/))){
|
|
|
|
$cb->({error => "$table table is not supported in tabdump -n. You may only use this option on the auditlog or the eventlog.",errorcode=>1});
|
|
|
|
return 1;
|
2013-08-06 16:15:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 12:44:10 +00:00
|
|
|
# do not allow teal tables
|
|
|
|
if ( $table =~ /^x_teal/ ) {
|
2013-08-01 16:07:30 +00:00
|
|
|
$cb->({error => "$table table is not supported in tabdump. Use Teal maintenance commands. ",errorcode=>1});
|
2011-05-12 12:44:10 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-02-21 21:10:35 +00:00
|
|
|
if ($DESC) { # only show the attribute descriptions, not the values
|
2011-03-20 06:53:44 +00:00
|
|
|
my $schema = xCAT::Table->getTableSchema($table);
|
|
|
|
if (!$schema) { $cb->({error => "table $table does not exist.",errorcode=>1}); return; }
|
|
|
|
my $desc = $schema->{descriptions};
|
|
|
|
foreach my $c (@{$schema->{cols}}) {
|
|
|
|
my $space = (length($c)<7 ? "\t\t" : "\t");
|
|
|
|
push @{$rsp{data}}, "$c:$space".$desc->{$c}."\n";
|
|
|
|
}
|
|
|
|
if (scalar(@{$rsp{data}})) { chop($rsp{data}->[scalar(@{$rsp{data}})-1]); } # remove the final newline
|
2008-02-21 21:10:35 +00:00
|
|
|
$cb->(\%rsp);
|
2011-03-20 06:53:44 +00:00
|
|
|
return;
|
2008-02-21 21:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-14 14:25:49 +00:00
|
|
|
my $tabh = xCAT::Table->new($table);
|
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
my $tabdump_header = sub {
|
2010-04-08 12:06:11 +00:00
|
|
|
my $header = "#" . join(",", @_);
|
|
|
|
push @{$rsp{data}}, $header;
|
2008-07-18 22:36:32 +00:00
|
|
|
};
|
2008-02-14 14:25:49 +00:00
|
|
|
|
|
|
|
# If the table does not exist yet (because its never been written to),
|
|
|
|
# at least show the header (the column names)
|
2008-02-06 15:21:54 +00:00
|
|
|
unless ($tabh)
|
|
|
|
{
|
|
|
|
if (defined($xCAT::Schema::tabspec{$table}))
|
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
$tabdump_header->(@{$xCAT::Schema::tabspec{$table}->{cols}});
|
|
|
|
$cb->(\%rsp);
|
2008-02-06 15:21:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-02-14 14:25:49 +00:00
|
|
|
$cb->({error => "No such table: $table",errorcode=>1});
|
2008-02-06 15:21:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2013-08-01 16:07:30 +00:00
|
|
|
#
|
|
|
|
# if tabdump -n <number of recs> auditlog|eventlog
|
|
|
|
#
|
|
|
|
if (defined $NUMBERENTRIES ) {
|
|
|
|
my $rc=tabdump_numberentries($table,$cb,$NUMBERENTRIES);
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:29:17 +00:00
|
|
|
my $recs;
|
|
|
|
my @ents;
|
|
|
|
my @attrarray;
|
2011-05-11 17:49:18 +00:00
|
|
|
if (!($FILENAME)) { # not dumping to a file
|
|
|
|
if (!($OPTW)) { # if no -w flag to filter, then get all
|
|
|
|
$recs = $tabh->getAllEntries("all");
|
|
|
|
} else { # filter entries
|
|
|
|
foreach my $w (@{$OPTW}){ # get each attr=val
|
|
|
|
push @attrarray, $w;
|
|
|
|
}
|
|
|
|
@ents = $tabh->getAllAttribsWhere(\@attrarray, 'ALL');
|
|
|
|
@$recs = ();
|
|
|
|
foreach my $e (@ents) {
|
|
|
|
push @$recs,$e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $rec;
|
|
|
|
unless (@$recs) # table exists, but is empty. Show header.
|
|
|
|
{
|
2011-03-29 19:29:17 +00:00
|
|
|
if (defined($xCAT::Schema::tabspec{$table}))
|
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
$tabdump_header->(@{$xCAT::Schema::tabspec{$table}->{cols}});
|
|
|
|
$cb->(\%rsp);
|
2008-02-06 15:21:54 +00:00
|
|
|
return;
|
2011-03-29 19:29:17 +00:00
|
|
|
}
|
2011-05-11 17:49:18 +00:00
|
|
|
}
|
|
|
|
#Display all the rows of the table the order of the columns in the schema
|
2011-03-29 19:29:17 +00:00
|
|
|
output_table($table,$cb,$tabh,$recs);
|
2011-05-11 17:49:18 +00:00
|
|
|
} else { # dump to file
|
|
|
|
|
|
|
|
my $rc1;
|
|
|
|
my $fh;
|
|
|
|
# check to see if you can open the file
|
|
|
|
unless (open($fh," > $FILENAME")) {
|
|
|
|
$cb->({error => "Error on tabdump of $table to $FILENAME. Unable to open the file for write. ",errorcode=>1});
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
close $fh;
|
|
|
|
if (!($OPTW)) { # if no -w flag to filter, then get all
|
|
|
|
$rc1=$tabh->writeAllEntries($FILENAME);
|
|
|
|
} else { # filter entries
|
|
|
|
foreach my $w (@{$OPTW}){ # get each attr=val
|
|
|
|
push @attrarray, $w;
|
|
|
|
}
|
|
|
|
$rc1 = $tabh->writeAllAttribsWhere(\@attrarray, $FILENAME);
|
|
|
|
}
|
|
|
|
if ($rc1 != 0) {
|
|
|
|
$cb->({error => "Error on tabdump of $table to $FILENAME ",errorcode=>1});
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2013-08-01 16:07:30 +00:00
|
|
|
#
|
|
|
|
# display input number of records for the table requested tabdump -n
|
2013-08-06 16:15:26 +00:00
|
|
|
# note currently only supports auditlog and eventlog
|
2013-08-01 16:07:30 +00:00
|
|
|
#
|
|
|
|
sub tabdump_numberentries {
|
|
|
|
my $table = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $numberentries = shift; # either number of records to display
|
|
|
|
|
|
|
|
my $VERBOSE = shift;
|
|
|
|
my $rc=0;
|
|
|
|
my $tab = xCAT::Table->new($table);
|
|
|
|
unless ($tab) {
|
|
|
|
$cb->({error => "Unable to open $table",errorcode=>4});
|
|
|
|
return 1;
|
|
|
|
}
|
2013-08-06 16:15:26 +00:00
|
|
|
#determine recid to show all records after
|
|
|
|
my $RECID;
|
|
|
|
my $attrrecid="recid";
|
|
|
|
my $values = $tab->getMAXMINEntries($attrrecid);
|
|
|
|
my $max=$values->{"max"};
|
|
|
|
if (defined($values->{"max"})){
|
|
|
|
$RECID= $values->{"max"} - $numberentries ;
|
|
|
|
$rc=tabdump_recid($table,$cb,$RECID, $attrrecid);
|
|
|
|
|
|
|
|
} else {
|
2013-08-01 16:07:30 +00:00
|
|
|
my %rsp;
|
|
|
|
push @{$rsp{data}}, "Nothing to display from $table.";
|
|
|
|
$rsp{errorcode} = $rc;
|
|
|
|
$cb->(\%rsp);
|
2013-08-06 16:15:26 +00:00
|
|
|
}
|
2013-08-01 16:07:30 +00:00
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
# Display requested recored
|
|
|
|
# if rec id does not exist error
|
|
|
|
sub tabdump_recid {
|
|
|
|
my $table = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $recid = shift;
|
|
|
|
my $rc=0;
|
|
|
|
# check which database so can build the correct Where clause
|
|
|
|
my $tab = xCAT::Table->new($table);
|
|
|
|
unless ($tab) {
|
|
|
|
$cb->({error => "Unable to open $table",errorcode=>4});
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
my $DBname = xCAT::Utils->get_DBName;
|
|
|
|
my @recs;
|
|
|
|
my $attrrecid="recid";
|
|
|
|
# display the output
|
|
|
|
if ($DBname =~ /^DB2/) {
|
|
|
|
@recs=$tab->getAllAttribsWhere("\"$attrrecid\">$recid", 'ALL');
|
|
|
|
} else {
|
|
|
|
@recs=$tab->getAllAttribsWhere("$attrrecid>$recid", 'ALL');
|
|
|
|
}
|
|
|
|
output_table($table,$cb,$tab,\@recs);
|
|
|
|
return $rc;
|
|
|
|
}
|
2013-08-06 16:15:26 +00:00
|
|
|
|
2010-10-27 15:27:04 +00:00
|
|
|
# Display information from the daemon.
|
|
|
|
#
|
|
|
|
sub lsxcatd
|
|
|
|
{
|
|
|
|
my $args = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $HELP;
|
|
|
|
my $VERSION;
|
|
|
|
my $DATABASE;
|
2012-02-02 13:45:51 +00:00
|
|
|
my $NODETYPE;
|
2010-10-27 15:27:04 +00:00
|
|
|
my $ALL;
|
|
|
|
my $rc=0;
|
|
|
|
|
|
|
|
my $lsxcatd_usage = sub {
|
2011-03-20 06:53:44 +00:00
|
|
|
my $exitcode = shift @_;
|
2010-10-27 15:27:04 +00:00
|
|
|
my %rsp;
|
|
|
|
push @{$rsp{data}}, " lsxcatd [-v|--version]";
|
|
|
|
push @{$rsp{data}}, " lsxcatd [-h|--help]";
|
|
|
|
push @{$rsp{data}}, " lsxcatd [-d|--database]";
|
2012-02-02 13:45:51 +00:00
|
|
|
push @{$rsp{data}}, " lsxcatd [-t|--nodetype]";
|
2010-10-27 15:27:04 +00:00
|
|
|
push @{$rsp{data}}, " lsxcatd [-a|--all]";
|
|
|
|
if ($exitcode) { $rsp{errorcode} = $exitcode; }
|
|
|
|
$cb->(\%rsp);
|
|
|
|
};
|
|
|
|
|
2011-03-20 06:53:44 +00:00
|
|
|
# Process arguments
|
2010-10-27 15:27:04 +00:00
|
|
|
if ($args) {
|
|
|
|
@ARGV = @{$args};
|
|
|
|
}
|
|
|
|
if (scalar(@ARGV)== 0) { $lsxcatd_usage->(1); return; }
|
|
|
|
if (!GetOptions('h|?|help' => \$HELP,
|
|
|
|
'v|version' => \$VERSION,
|
2011-03-17 07:16:24 +00:00
|
|
|
'a|all' => \$ALL,
|
2012-02-02 13:45:51 +00:00
|
|
|
't|type' => \$NODETYPE,
|
2010-10-27 15:27:04 +00:00
|
|
|
'd|database' => \$DATABASE))
|
|
|
|
{ $lsxcatd_usage->(1); return; }
|
|
|
|
|
|
|
|
if ($HELP) { $lsxcatd_usage->(0); return; }
|
|
|
|
# Version
|
2011-06-16 12:57:50 +00:00
|
|
|
if ($VERSION || $ALL) {
|
2010-10-27 15:27:04 +00:00
|
|
|
my %rsp;
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
$rsp{data}->[0] = "$version";
|
|
|
|
$cb->(\%rsp);
|
2011-06-16 12:57:50 +00:00
|
|
|
if (!$ALL) {
|
2010-10-27 15:27:04 +00:00
|
|
|
return;
|
2011-06-16 12:57:50 +00:00
|
|
|
}
|
2010-10-27 15:27:04 +00:00
|
|
|
}
|
2012-02-02 13:45:51 +00:00
|
|
|
# nodetype MN or SN
|
|
|
|
if ($NODETYPE || $ALL) {
|
|
|
|
my %rsp;
|
|
|
|
if (xCAT::Utils->isMN()) { # if on Management Node
|
|
|
|
$rsp{data}->[0] = "This is a Management Node";
|
|
|
|
$cb->(\%rsp);
|
|
|
|
}
|
|
|
|
if (xCAT::Utils->isServiceNode()) { # if on Management Node
|
|
|
|
$rsp{data}->[0] = "This is a Service Node";
|
|
|
|
$cb->(\%rsp);
|
|
|
|
}
|
|
|
|
if (!$ALL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-10-27 15:27:04 +00:00
|
|
|
# no arguments error
|
|
|
|
my $xcatcfg;
|
|
|
|
my %rsp;
|
|
|
|
if ($DATABASE || $ALL) {
|
|
|
|
$xcatcfg = xCAT::Table->get_xcatcfg();
|
|
|
|
|
|
|
|
if ($xcatcfg =~ /^SQLite:/) { # SQLite just return SQlite
|
|
|
|
$rsp{data}->[0] = "dbengine=SQLite";
|
|
|
|
$cb->(\%rsp);
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($xcatcfg =~ /^DB2:/) { # for DB2 , get schema name
|
|
|
|
my @parts = split ( '\|', $xcatcfg);
|
|
|
|
my $cfgloc=$parts[0] ."|" . $parts[1] ;
|
|
|
|
my $instance;
|
|
|
|
$instance = $parts[1];
|
|
|
|
my ($db2,$databasename)= split(':',$parts[0]);
|
2011-04-14 16:53:58 +00:00
|
|
|
my $xcatdbhome = xCAT::Utils->getHomeDir("xcatdb");
|
2010-10-27 15:27:04 +00:00
|
|
|
$rsp{data}->[0] = "cfgloc=$cfgloc";
|
|
|
|
$rsp{data}->[1] = "dbengine=$db2";
|
|
|
|
$rsp{data}->[2] = "dbinstance=$instance";
|
2011-04-14 16:53:58 +00:00
|
|
|
$rsp{data}->[3] = "dbname=$databasename";
|
|
|
|
$rsp{data}->[4] = "dbloc=$xcatdbhome";
|
|
|
|
|
2010-10-27 15:27:04 +00:00
|
|
|
$cb->(\%rsp);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (($xcatcfg =~ /^mysql:/) ||($xcatcfg =~ /^Pg:/)) {
|
|
|
|
my @parts = split ( '\|', $xcatcfg);
|
|
|
|
my $cfgloc=$parts[0] ."|". $parts[1] ;
|
|
|
|
my ($host,$addr) = split('host=',$parts[0]);
|
|
|
|
my ($engine,$databasenamestr) = split(':',$host);
|
|
|
|
my ($db,$databasename) = split('=',$databasenamestr);
|
|
|
|
chop $databasename;
|
|
|
|
|
|
|
|
$rsp{data}->[0] = "cfgloc=$cfgloc";
|
|
|
|
$rsp{data}->[1] = "dbengine=$engine";
|
|
|
|
$rsp{data}->[2] = "dbname=$databasename";
|
|
|
|
$rsp{data}->[3] = "dbhost=$addr";
|
|
|
|
$rsp{data}->[4] = "dbadmin=$parts[1]";
|
|
|
|
$cb->(\%rsp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rc;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2010-03-31 18:01:59 +00:00
|
|
|
# Prune records from the eventlog or auditlog or all records.
|
2010-03-31 14:07:19 +00:00
|
|
|
# Only supports eventlog and auditlog
|
|
|
|
sub tabprune
|
|
|
|
{
|
|
|
|
my $args = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $HELP;
|
|
|
|
my $VERSION;
|
|
|
|
my $ALL;
|
|
|
|
my $NUMBERENTRIES;
|
|
|
|
my $PERCENT;
|
2010-04-07 17:51:37 +00:00
|
|
|
my $VERBOSE;
|
2010-03-31 14:07:19 +00:00
|
|
|
my $RECID;
|
2011-09-14 11:06:02 +00:00
|
|
|
my $NUMBERDAYS;
|
2010-03-31 18:01:59 +00:00
|
|
|
my $rc=0;
|
2010-03-31 14:07:19 +00:00
|
|
|
|
|
|
|
my $tabprune_usage = sub {
|
2011-03-20 06:53:44 +00:00
|
|
|
my $exitcode = shift @_;
|
2010-03-31 14:07:19 +00:00
|
|
|
my %rsp;
|
2011-04-27 16:04:37 +00:00
|
|
|
push @{$rsp{data}}, "Usage: tabprune <tablename> [-V] -a";
|
|
|
|
push @{$rsp{data}}, " tabprune <tablename> [-V] -n <# of records>";
|
|
|
|
push @{$rsp{data}}, " tabprune <tablename> [-V] -i <recid>";
|
|
|
|
push @{$rsp{data}}, " tabprune <tablename> [-V] -p <percent>";
|
2011-09-14 11:06:02 +00:00
|
|
|
push @{$rsp{data}}, " tabprune <tablename> [-V] -d <# of days>";
|
2010-03-31 14:35:49 +00:00
|
|
|
push @{$rsp{data}}, " tabprune [-h|--help]";
|
|
|
|
push @{$rsp{data}}, " tabprune [-v|--version]";
|
2013-08-01 16:07:30 +00:00
|
|
|
push @{$rsp{data}}, " tables supported:eventlog,auditlog";
|
2011-09-14 11:06:02 +00:00
|
|
|
push @{$rsp{data}}, " -d option only supported for eventlog,auditlog";
|
2010-03-31 14:07:19 +00:00
|
|
|
if ($exitcode) { $rsp{errorcode} = $exitcode; }
|
|
|
|
$cb->(\%rsp);
|
|
|
|
};
|
|
|
|
|
2011-03-20 06:53:44 +00:00
|
|
|
# Process arguments
|
2010-03-31 14:07:19 +00:00
|
|
|
if ($args) {
|
|
|
|
@ARGV = @{$args};
|
|
|
|
}
|
|
|
|
if (!GetOptions('h|?|help' => \$HELP,
|
|
|
|
'v|version' => \$VERSION,
|
2010-04-07 17:51:37 +00:00
|
|
|
'V' => \$VERBOSE,
|
2010-03-31 14:07:19 +00:00
|
|
|
'p|percent=i' => \$PERCENT,
|
2011-09-14 11:06:02 +00:00
|
|
|
'd|days=i' => \$NUMBERDAYS,
|
2010-03-31 14:07:19 +00:00
|
|
|
'i|recid=s' => \$RECID,
|
|
|
|
'a' => \$ALL,
|
|
|
|
'n|number=i' => \$NUMBERENTRIES))
|
|
|
|
{ $tabprune_usage->(1); return; }
|
|
|
|
|
|
|
|
if ($HELP) { $tabprune_usage->(0); return; }
|
|
|
|
# Version
|
|
|
|
if ($VERSION) {
|
|
|
|
my %rsp;
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
$rsp{data}->[0] = "$version";
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (scalar(@ARGV)>1) { $tabprune_usage->(1); return; }
|
|
|
|
my $table = $ARGV[0];
|
2010-03-31 14:35:49 +00:00
|
|
|
if (!(defined $table)) {
|
|
|
|
my %rsp;
|
2011-04-27 16:04:37 +00:00
|
|
|
$rsp{data}->[0] = "Table name required.";
|
2010-03-31 14:35:49 +00:00
|
|
|
$rsp{errorcode} = 1;
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
$table=~ s/\s*//g; # remove blanks
|
2011-04-27 16:04:37 +00:00
|
|
|
if (($table ne "eventlog") && ($table ne "auditlog") && ($table ne "isnm_perf") && ($table ne "isnm_perf_sum") ) {
|
2010-03-31 14:35:49 +00:00
|
|
|
my %rsp;
|
2011-04-27 16:04:37 +00:00
|
|
|
$rsp{data}->[0] = "Table $table not supported, see tabprune -h for supported tables.";
|
2010-03-31 14:35:49 +00:00
|
|
|
$rsp{errorcode} = 1;
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return 1;
|
|
|
|
|
2011-09-14 11:06:02 +00:00
|
|
|
}
|
|
|
|
# only support days option for eventlog and auditlog
|
|
|
|
if (($table ne "eventlog") && ($table ne "auditlog") && (defined $NUMBERDAYS) ) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0] = "Table $table not supported for the -d option.";
|
|
|
|
$rsp{errorcode} = 1;
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return 1;
|
|
|
|
|
2010-05-06 18:53:17 +00:00
|
|
|
}
|
2011-09-14 11:06:02 +00:00
|
|
|
if ((!(defined $PERCENT )) && (!(defined $NUMBERDAYS))&& (!(defined $RECID)) && (!(defined $ALL)) && (!(defined $NUMBERENTRIES))) {
|
2010-05-06 18:53:17 +00:00
|
|
|
my %rsp;
|
2011-09-14 11:06:02 +00:00
|
|
|
$rsp{data}->[0] = "One option -p or -i or -n or -a or -d must be supplied.";
|
2010-05-06 18:53:17 +00:00
|
|
|
$rsp{errorcode} = 1;
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return 1;
|
|
|
|
|
2010-03-31 14:35:49 +00:00
|
|
|
}
|
2010-03-31 18:01:59 +00:00
|
|
|
if ((defined $PERCENT ) && ((defined $RECID) || (defined $ALL) || (defined $NUMBERENTRIES))) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0] = "Only one option -p or -i or -n or -a maybe used at a time.";
|
|
|
|
$rsp{errorcode} = 1;
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ((defined $RECID ) && ((defined $PERCENT) || (defined $ALL) || (defined $NUMBERENTRIES))) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0] = "Only one option -p or -i or -n or -a maybe used at a time.";
|
|
|
|
$rsp{errorcode} = 1;
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ((defined $ALL ) && ((defined $PERCENT) || (defined $RECID) || (defined $NUMBERENTRIES))) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0] = "Only one option -p or -i or -n or -a maybe used at a time.";
|
|
|
|
$rsp{errorcode} = 1;
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if ((defined $NUMBERENTRIES ) && ((defined $PERCENT) || (defined $RECID) || (defined $ALL))) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0] = "Only one option -p or -i or -n or -a maybe used at a time.";
|
|
|
|
$rsp{errorcode} = 1;
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return 1;
|
2011-02-22 17:12:56 +00:00
|
|
|
}
|
|
|
|
# determine the attribute name of the recid
|
|
|
|
my $attrrecid;
|
|
|
|
if (($table eq "eventlog") || ($table eq "auditlog")) {
|
|
|
|
$attrrecid="recid";
|
2011-04-27 16:04:37 +00:00
|
|
|
} else {
|
2013-08-06 16:15:26 +00:00
|
|
|
if ($table eq "isnm_perf") { # if ISNM These tables are really not supported in 2.8 or later
|
2011-04-27 16:04:37 +00:00
|
|
|
$attrrecid="perfid";
|
|
|
|
} else {
|
|
|
|
$attrrecid="period"; # isnm_perf_sum table
|
|
|
|
}
|
2011-02-22 17:12:56 +00:00
|
|
|
}
|
2010-03-31 18:01:59 +00:00
|
|
|
if (defined $ALL ) {
|
2011-02-22 17:12:56 +00:00
|
|
|
$rc=tabprune_all($table,$cb, $attrrecid,$VERBOSE);
|
2010-03-31 18:01:59 +00:00
|
|
|
}
|
2010-04-05 19:44:12 +00:00
|
|
|
if (defined $NUMBERENTRIES ) {
|
2011-02-22 17:12:56 +00:00
|
|
|
$rc=tabprune_numberentries($table,$cb,$NUMBERENTRIES,"n", $attrrecid,$VERBOSE);
|
2010-04-07 14:42:03 +00:00
|
|
|
}
|
|
|
|
if (defined $PERCENT) {
|
2011-02-22 17:12:56 +00:00
|
|
|
$rc=tabprune_numberentries($table,$cb,$PERCENT,"p", $attrrecid,$VERBOSE);
|
2010-04-05 19:44:12 +00:00
|
|
|
}
|
|
|
|
if (defined $RECID ) {
|
2011-02-22 17:12:56 +00:00
|
|
|
$rc=tabprune_recid($table,$cb,$RECID, $attrrecid,$VERBOSE);
|
2010-04-07 17:51:37 +00:00
|
|
|
}
|
2011-09-14 11:06:02 +00:00
|
|
|
if (defined $NUMBERDAYS ) {
|
|
|
|
$rc=tabprune_numberdays($table,$cb,$NUMBERDAYS, $attrrecid,$VERBOSE);
|
|
|
|
}
|
2010-04-07 17:51:37 +00:00
|
|
|
if (!($VERBOSE)) { # not putting out changes
|
|
|
|
my %rsp;
|
|
|
|
push @{$rsp{data}}, "tabprune of $table complete.";
|
|
|
|
$rsp{errorcode} = $rc;
|
|
|
|
$cb->(\%rsp);
|
2010-04-05 19:44:12 +00:00
|
|
|
}
|
2010-03-31 18:01:59 +00:00
|
|
|
return $rc;
|
2010-03-31 14:07:19 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 18:01:59 +00:00
|
|
|
sub tabprune_all {
|
|
|
|
my $table = shift;
|
|
|
|
my $cb = shift;
|
2011-02-22 17:12:56 +00:00
|
|
|
my $attrrecid = shift;
|
2010-04-07 17:51:37 +00:00
|
|
|
my $VERBOSE = shift;
|
2010-03-31 18:01:59 +00:00
|
|
|
my $rc=0;
|
2010-04-06 14:52:10 +00:00
|
|
|
my $tab = xCAT::Table->new($table);
|
2010-03-31 18:01:59 +00:00
|
|
|
unless ($tab) {
|
2010-04-07 12:41:52 +00:00
|
|
|
$cb->({error => "Unable to open $table",errorcode=>4});
|
2010-03-31 18:01:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2010-04-07 17:51:37 +00:00
|
|
|
if ($VERBOSE) { # will output change to std
|
|
|
|
my $recs = $tab->getAllEntries("all");
|
2010-04-08 12:06:11 +00:00
|
|
|
output_table($table,$cb,$tab,$recs);
|
2010-04-07 17:51:37 +00:00
|
|
|
}
|
|
|
|
|
2010-03-31 18:01:59 +00:00
|
|
|
$tab->delEntries(); #Yes, delete *all* entries
|
|
|
|
$tab->commit; # commit
|
|
|
|
return $rc;
|
|
|
|
}
|
2010-04-07 12:41:52 +00:00
|
|
|
|
2010-04-07 14:42:03 +00:00
|
|
|
# prune input number of records for the table
|
2010-04-05 19:44:12 +00:00
|
|
|
# if number of entries > number than in the table, then remove all
|
2010-04-07 14:42:03 +00:00
|
|
|
# this handles the number of records or percentage to delete
|
2010-04-07 12:41:52 +00:00
|
|
|
sub tabprune_numberentries {
|
|
|
|
my $table = shift;
|
|
|
|
my $cb = shift;
|
2010-04-07 14:42:03 +00:00
|
|
|
my $numberentries = shift; # either number of entries or percent to
|
|
|
|
# remove based on the flag
|
|
|
|
my $flag = shift; # (n or p flag)
|
2011-02-22 17:12:56 +00:00
|
|
|
my $attrrecid = shift;
|
2010-04-07 17:51:37 +00:00
|
|
|
my $VERBOSE = shift;
|
2010-04-07 12:41:52 +00:00
|
|
|
my $rc=0;
|
|
|
|
my $tab = xCAT::Table->new($table);
|
|
|
|
unless ($tab) {
|
|
|
|
$cb->({error => "Unable to open $table",errorcode=>4});
|
|
|
|
return 1;
|
|
|
|
}
|
2013-08-06 16:15:26 +00:00
|
|
|
my $RECID;
|
|
|
|
my $values = $tab->getMAXMINEntries($attrrecid);
|
|
|
|
if ((defined($values->{"max"})) && (defined($values->{"min"}))) {
|
|
|
|
my $largerid = $values->{"max"};
|
|
|
|
my $smallrid = $values->{"min"};
|
2011-04-27 16:04:37 +00:00
|
|
|
if ($flag eq "n") { # deleting number of records
|
2013-08-06 16:15:26 +00:00
|
|
|
#get the smalled recid and add number to delete, that is where to start removing
|
|
|
|
$RECID= $smallrid + $numberentries ;
|
2011-04-27 16:04:37 +00:00
|
|
|
} else { # flag must be percentage
|
|
|
|
#take largest and smallest recid and percentage and determine the recid
|
|
|
|
# that will remove the requested percentage. If some are missing in the
|
|
|
|
# middle due to tabedit, we are not worried about it.
|
2010-04-07 14:42:03 +00:00
|
|
|
|
2013-08-06 16:15:26 +00:00
|
|
|
my $totalnumberrids = $largerid - $smallrid +1;
|
2011-04-27 16:04:37 +00:00
|
|
|
my $percent = $numberentries / 100;
|
|
|
|
my $percentage=$totalnumberrids * $percent ;
|
|
|
|
my $cnt=sprintf( "%d", $percentage ); # round to whole number
|
2013-08-06 16:15:26 +00:00
|
|
|
$RECID=$smallrid + $cnt; # get recid to remove all before
|
2011-04-27 16:04:37 +00:00
|
|
|
}
|
2013-08-06 16:15:26 +00:00
|
|
|
# Now prune starting at $RECID
|
2011-04-27 16:04:37 +00:00
|
|
|
$rc=tabprune_recid($table,$cb,$RECID, $attrrecid,$VERBOSE);
|
2013-08-06 16:15:26 +00:00
|
|
|
} else {
|
2011-04-27 16:04:37 +00:00
|
|
|
my %rsp;
|
|
|
|
push @{$rsp{data}}, "Nothing to prune from $table.";
|
|
|
|
$rsp{errorcode} = $rc;
|
|
|
|
$cb->(\%rsp);
|
2013-08-06 16:15:26 +00:00
|
|
|
}
|
|
|
|
return $rc;
|
2010-04-07 12:41:52 +00:00
|
|
|
}
|
2010-04-05 19:44:12 +00:00
|
|
|
|
|
|
|
# prune all entries up to the record id input
|
|
|
|
# if rec id does not exist error
|
|
|
|
sub tabprune_recid {
|
|
|
|
my $table = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $recid = shift;
|
2011-02-22 17:12:56 +00:00
|
|
|
my $attrrecid = shift;
|
2010-04-07 17:51:37 +00:00
|
|
|
my $VERBOSE = shift;
|
2010-04-05 19:44:12 +00:00
|
|
|
my $rc=0;
|
2010-04-06 13:34:11 +00:00
|
|
|
# check which database so can build the correct Where clause
|
2010-04-06 14:52:10 +00:00
|
|
|
my $tab = xCAT::Table->new($table);
|
2010-04-05 19:44:12 +00:00
|
|
|
unless ($tab) {
|
|
|
|
$cb->({error => "Unable to open $table",errorcode=>4});
|
|
|
|
return 1;
|
|
|
|
}
|
2010-04-07 12:41:52 +00:00
|
|
|
my $DBname = xCAT::Utils->get_DBName;
|
2010-04-09 14:00:43 +00:00
|
|
|
# display the output
|
|
|
|
my @recs;
|
|
|
|
if ($VERBOSE) { # need to get all attributes
|
|
|
|
if ($DBname =~ /^DB2/) {
|
2011-02-22 17:12:56 +00:00
|
|
|
@recs=$tab->getAllAttribsWhere("\"$attrrecid\"<$recid", 'ALL');
|
2010-04-09 14:00:43 +00:00
|
|
|
} else {
|
2011-02-22 17:12:56 +00:00
|
|
|
@recs=$tab->getAllAttribsWhere("$attrrecid<$recid", 'ALL');
|
2010-04-09 14:00:43 +00:00
|
|
|
}
|
|
|
|
output_table($table,$cb,$tab,\@recs);
|
|
|
|
}
|
2010-04-06 13:34:11 +00:00
|
|
|
my @ents;
|
|
|
|
if ($DBname =~ /^DB2/) {
|
2011-02-22 17:12:56 +00:00
|
|
|
@ents=$tab->getAllAttribsWhere("\"$attrrecid\"<$recid", $attrrecid);
|
2010-04-06 13:34:11 +00:00
|
|
|
} else {
|
2011-02-22 17:12:56 +00:00
|
|
|
@ents=$tab->getAllAttribsWhere("$attrrecid<$recid", $attrrecid);
|
2010-04-09 14:00:43 +00:00
|
|
|
}
|
|
|
|
# delete them
|
2010-04-05 19:44:12 +00:00
|
|
|
foreach my $rid (@ents) {
|
|
|
|
$tab->delEntries($rid);
|
|
|
|
}
|
|
|
|
$tab->commit;
|
|
|
|
return $rc;
|
|
|
|
}
|
2011-09-14 11:06:02 +00:00
|
|
|
# prune all record up to number of days from today
|
|
|
|
sub tabprune_numberdays {
|
|
|
|
my $table = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $numberdays = shift;
|
|
|
|
my $attrrecid = shift;
|
|
|
|
my $VERBOSE = shift;
|
|
|
|
my $rc=0;
|
|
|
|
# check which database so can build the correct Where clause
|
|
|
|
my $tab = xCAT::Table->new($table);
|
|
|
|
unless ($tab) {
|
|
|
|
$cb->({error => "Unable to open $table",errorcode=>4});
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
# get number of seconds in the day count
|
|
|
|
my $numbersecs=($numberdays * 86400);
|
|
|
|
# get time now
|
|
|
|
my $timenow=time;
|
|
|
|
my $secsdaysago=$timenow - $numbersecs;
|
|
|
|
# Format like the database table timestamp record
|
|
|
|
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
|
|
|
|
localtime($secsdaysago);
|
|
|
|
my $daysago = sprintf("%04d-%02d-%02d %02d:%02d:%02d",
|
|
|
|
$year + 1900, $mon + 1, $mday,
|
|
|
|
$hour, $min, $sec);
|
|
|
|
# delete all records before # days ago
|
|
|
|
|
2013-10-10 13:07:45 +00:00
|
|
|
# display the output
|
|
|
|
# get field name for the table
|
|
|
|
my $timeattr="audittime"; # default auditlog, most used
|
|
|
|
if ($table eq "eventlog") {
|
|
|
|
$timeattr="eventtime";
|
|
|
|
}
|
2011-09-14 11:06:02 +00:00
|
|
|
my @attrarray;
|
2013-10-10 13:07:45 +00:00
|
|
|
push @attrarray, "$timeattr<$daysago";
|
2011-09-14 11:06:02 +00:00
|
|
|
my @recs;
|
|
|
|
if ($VERBOSE) { # need to get all attributes
|
|
|
|
@recs = $tab->getAllAttribsWhere(\@attrarray, 'ALL');
|
|
|
|
output_table($table,$cb,$tab,\@recs);
|
|
|
|
}
|
|
|
|
my @ents = $tab->getAllAttribsWhere(\@attrarray, $attrrecid);
|
|
|
|
# delete them
|
|
|
|
foreach my $rid (@ents) {
|
|
|
|
$tab->delEntries($rid);
|
|
|
|
}
|
|
|
|
$tab->commit;
|
|
|
|
return $rc;
|
|
|
|
}
|
|
|
|
|
2010-04-05 19:44:12 +00:00
|
|
|
|
2010-04-08 12:06:11 +00:00
|
|
|
# Dump table records to stdout.
|
|
|
|
sub output_table {
|
2010-04-07 17:51:37 +00:00
|
|
|
my $table = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $tabh=shift;
|
|
|
|
my $recs=shift;
|
|
|
|
my %rsp;
|
|
|
|
my $tabdump_header = sub {
|
|
|
|
my $header = "#" . join(",", @_);
|
|
|
|
push @{$rsp{data}}, $header;
|
|
|
|
};
|
|
|
|
# Display all the rows of the table in order of the columns in the schema
|
|
|
|
$tabdump_header->(@{$tabh->{colnames}});
|
|
|
|
foreach my $rec (@$recs)
|
|
|
|
{
|
|
|
|
my $line = '';
|
|
|
|
foreach (@{$tabh->{colnames}})
|
|
|
|
{
|
|
|
|
if (defined $rec->{$_})
|
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
$rec->{$_} =~ s/"/""/g;
|
2010-04-07 17:51:37 +00:00
|
|
|
$line = $line . '"' . $rec->{$_} . '",';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$line .= ',';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$line =~ s/,$//; # remove the extra comma at the end
|
|
|
|
push @{$rsp{data}}, $line;
|
|
|
|
}
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-07 20:43:03 +00:00
|
|
|
sub getTableColumn {
|
|
|
|
my $string = shift;
|
|
|
|
if ($shortnames{$string}) {
|
|
|
|
return @{$shortnames{$string}};
|
|
|
|
}
|
|
|
|
unless ($string =~ /\./) {
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
return split /\./,$string,2;
|
|
|
|
}
|
|
|
|
|
2009-09-29 20:41:13 +00:00
|
|
|
# sub groupch
|
|
|
|
# {
|
|
|
|
# my $args = shift;
|
|
|
|
# my $nodech_usage = sub
|
|
|
|
# {
|
|
|
|
# my $exitcode = shift @_;
|
|
|
|
# my $cmdname = "groupch";
|
|
|
|
# my %rsp;
|
|
|
|
# push @{$rsp{data}}, "Usage: $cmdname <group1,group2,...> table.column=value [...]";
|
|
|
|
# push @{$rsp{data}}, " $cmdname {-v | --version}";
|
|
|
|
# push @{$rsp{data}}, " $cmdname [-? | -h | --help]";
|
|
|
|
# if ($exitcode) { $rsp{errorcode} = $exitcode; }
|
|
|
|
# $callback->(\%rsp);
|
|
|
|
# };
|
|
|
|
# my @args = @{$args};
|
|
|
|
# unless (scalar @args >= 2) {
|
|
|
|
# $nodech_usage->(1);
|
|
|
|
# return;
|
|
|
|
# }
|
|
|
|
# my @groups = split /,/,shift @args;
|
|
|
|
# foreach (@args)
|
|
|
|
# {
|
|
|
|
# # if ($deletemode)
|
|
|
|
# # {
|
|
|
|
# # if (m/[=\.]/) # in delete mode they can only specify tables names
|
|
|
|
# # {
|
|
|
|
# # $callback->({error => [". and = not valid in delete mode."],errorcode=>1});
|
|
|
|
# # next;
|
|
|
|
# # }
|
|
|
|
# # $tables{$_} = 1;
|
|
|
|
# # next;
|
|
|
|
# # }
|
|
|
|
# unless (m/=/ or m/!~/)
|
|
|
|
# {
|
|
|
|
# $callback->({error => ["Malformed argument $_ ignored."],errorcode=>1});
|
|
|
|
# next;
|
|
|
|
# }
|
|
|
|
# my $stable;
|
|
|
|
# my $scolumn;
|
|
|
|
# #Check for selection criteria
|
|
|
|
# if (m/^[^=]*==/) {
|
|
|
|
# ($temp,$value)=split /==/,$_,2;
|
|
|
|
# ($stable,$scolumn)=getTableColumn($temp);
|
|
|
|
# $criteria{$stable}->{$scolumn}=[$value,'match'];
|
|
|
|
|
|
|
|
# next; #Is a selection criteria, not an assignment specification
|
|
|
|
# } elsif (m/^[^=]*!=/) {
|
|
|
|
# ($temp,$value)=split /!=/,$_,2;
|
|
|
|
# ($stable,$scolumn)=getTableColumn($temp);
|
|
|
|
# $criteria{$stable}->{$scolumn}=[$value,'natch'];
|
|
|
|
# next; #Is a selection criteria, not an assignment specification
|
|
|
|
# } elsif (m/^[^=]*=~/) {
|
|
|
|
# ($temp,$value)=split /=~/,$_,2;
|
|
|
|
# ($stable,$scolumn)=getTableColumn($temp);
|
|
|
|
# $value =~ s/^\///;
|
|
|
|
# $value =~ s/\/$//;
|
|
|
|
# $criteria{$stable}->{$scolumn}=[$value,'regex'];
|
|
|
|
# next; #Is a selection criteria, not an assignment specification
|
|
|
|
# } elsif (m/^[^=]*!~/) {
|
|
|
|
# ($temp,$value)=split /!~/,$_,2;
|
|
|
|
# ($stable,$scolumn)=getTableColumn($temp);
|
|
|
|
# $value =~ s/^\///;
|
|
|
|
# $value =~ s/\/$//;
|
|
|
|
# $criteria{$stable}->{$scolumn}=[$value,'negex'];
|
|
|
|
# next; #Is a selection criteria, not an assignment specification
|
|
|
|
# }
|
|
|
|
# #Now definitely an assignment
|
|
|
|
#
|
|
|
|
# ($temp, $value) = split('=', $_, 2);
|
|
|
|
# $value =~ s/^@//; #Allow the =@ operator to exist for an unambiguous assignmenet operator
|
|
|
|
# #So before, table.column==value meant set to =value, now it would be matching value
|
|
|
|
# #the new way would be table.column=@=value to be unambiguous
|
|
|
|
# #now a value like '@hi' would be set with table.column=@@hi
|
|
|
|
# if ($value eq '') { #If blank, force a null entry to override group settings
|
|
|
|
# $value = '|^.*$||';
|
|
|
|
# }
|
|
|
|
# my $op = '=';
|
|
|
|
# if ($temp =~ /,$/)
|
|
|
|
# {
|
|
|
|
# $op = ',=';
|
|
|
|
# chop($temp);
|
|
|
|
# }
|
|
|
|
# elsif ($temp =~ /\^$/)
|
|
|
|
# {
|
|
|
|
# $op = '^=';
|
|
|
|
# chop($temp);
|
|
|
|
# }
|
|
|
|
|
|
|
|
# my $table;
|
|
|
|
# if ($shortnames{$temp})
|
|
|
|
# {
|
|
|
|
# ($table, $column) = @{$shortnames{$temp}};
|
|
|
|
# }
|
|
|
|
# else
|
|
|
|
# {
|
|
|
|
# ($table, $column) = split('\.', $temp, 2);
|
|
|
|
# }
|
|
|
|
# unless (grep /$column/,@{$xCAT::Schema::tabspec{$table}->{cols}}) {
|
|
|
|
# $callback->({error=>"$table.$column not a valid table.column description",errorcode=>[1]});
|
|
|
|
# return;
|
|
|
|
# }
|
|
|
|
|
|
|
|
# # Keep a list of the value/op pairs, in case there is more than 1 per table.column
|
|
|
|
# #$tables{$table}->{$column} = [$value, $op];
|
|
|
|
# push @{$tables{$table}->{$column}}, ($value, $op);
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
2012-09-12 13:45:34 +00:00
|
|
|
#
|
|
|
|
# Process the nodech command, also used by the XML setNodesAttribs utility
|
|
|
|
# in tabutils
|
|
|
|
#
|
2008-02-14 14:25:49 +00:00
|
|
|
sub nodech
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
|
|
|
my $nodes = shift;
|
|
|
|
my $args = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $addmode = shift;
|
2009-09-29 20:41:13 +00:00
|
|
|
my $groupmode;
|
|
|
|
if ($addmode eq "groupch") {
|
|
|
|
$addmode = 0;
|
|
|
|
$groupmode=1;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
my $VERSION;
|
|
|
|
my $HELP;
|
2008-03-08 14:14:00 +00:00
|
|
|
my $deletemode;
|
2009-06-02 05:29:55 +00:00
|
|
|
my $grptab;
|
|
|
|
my @grplist;
|
2008-02-06 15:21:54 +00:00
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
my $nodech_usage = sub
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
my $exitcode = shift @_;
|
|
|
|
my $addmode = shift @_;
|
2009-09-29 20:41:13 +00:00
|
|
|
my $groupmode = shift @_;
|
2011-03-20 06:53:44 +00:00
|
|
|
my $cmdname = $addmode ? 'nodeadd' : ($groupmode ? 'nodegrpch' : 'nodech');
|
2008-02-06 15:21:54 +00:00
|
|
|
my %rsp;
|
2008-03-08 14:14:00 +00:00
|
|
|
if ($addmode) {
|
2011-03-20 06:53:44 +00:00
|
|
|
push @{$rsp{data}}, "Usage: $cmdname <noderange> groups=<groupnames> [table.column=value] [...]";
|
2009-09-29 20:41:13 +00:00
|
|
|
} elsif ($groupmode) {
|
2011-03-20 06:53:44 +00:00
|
|
|
push @{$rsp{data}}, "Usage: $cmdname <group1,group2,...> [table.column=value] [...]";
|
2008-03-08 14:14:00 +00:00
|
|
|
} else {
|
2011-03-20 06:53:44 +00:00
|
|
|
push @{$rsp{data}}, "Usage: $cmdname <noderange> table.column=value [...]";
|
|
|
|
push @{$rsp{data}}, " $cmdname {-d | --delete} <noderange> <table> [...]";
|
2008-03-08 14:14:00 +00:00
|
|
|
}
|
|
|
|
push @{$rsp{data}}, " $cmdname {-v | --version}";
|
|
|
|
push @{$rsp{data}}, " $cmdname [-? | -h | --help]";
|
|
|
|
if ($exitcode) { $rsp{errorcode} = $exitcode; }
|
|
|
|
$callback->(\%rsp);
|
2008-07-18 22:36:32 +00:00
|
|
|
};
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-10-31 13:38:57 +00:00
|
|
|
if ($args) {
|
|
|
|
@ARGV = @{$args};
|
|
|
|
} else {
|
|
|
|
@ARGV=();
|
|
|
|
}
|
2008-03-08 14:14:00 +00:00
|
|
|
my %options = ('h|?|help' => \$HELP, 'v|version' => \$VERSION);
|
|
|
|
if (!$addmode) { $options{'d|delete'} = \$deletemode; }
|
|
|
|
if (!GetOptions(%options)) {
|
2009-09-29 20:41:13 +00:00
|
|
|
$nodech_usage->(1, $addmode,$groupmode);
|
2008-03-08 14:14:00 +00:00
|
|
|
return;
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Help
|
2008-03-08 14:14:00 +00:00
|
|
|
if ($HELP) {
|
2009-09-29 20:41:13 +00:00
|
|
|
$nodech_usage->(0, $addmode,$groupmode);
|
2008-02-06 15:21:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
# Version
|
2008-03-08 14:14:00 +00:00
|
|
|
if ($VERSION) {
|
2008-02-06 15:21:54 +00:00
|
|
|
my %rsp;
|
2008-07-07 18:29:55 +00:00
|
|
|
my $version = xCAT::Utils->Version();
|
2008-07-18 19:37:43 +00:00
|
|
|
$rsp{data}->[0] = "$version";
|
|
|
|
$callback->(\%rsp);
|
2008-02-06 15:21:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-03-08 14:14:00 +00:00
|
|
|
|
|
|
|
# Note: the noderange comes through in $arg (and therefore @ARGV) for nodeadd,
|
|
|
|
# because it is linked to xcatclientnnr, since the nodes specified in the noderange
|
|
|
|
# do not exist yet. The nodech cmd is linked to xcatclient, so its noderange is
|
|
|
|
# put in $nodes instead of $args.
|
2008-07-18 22:36:32 +00:00
|
|
|
if (scalar(@ARGV) < (1+$addmode)) { $nodech_usage->(1, $addmode); return; }
|
2009-09-29 20:41:13 +00:00
|
|
|
my @groups;
|
2008-03-08 14:14:00 +00:00
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
if ($addmode)
|
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
my $nr = shift @ARGV;
|
|
|
|
$nodes = [noderange($nr, 0)];
|
2008-03-08 14:14:00 +00:00
|
|
|
unless ($nodes) {
|
|
|
|
$callback->({error => "No noderange to add.\n",errorcode=>1});
|
2008-02-06 15:21:54 +00:00
|
|
|
return;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2010-03-24 14:51:26 +00:00
|
|
|
|
|
|
|
my $invalidnodename = ();
|
|
|
|
foreach my $node (@$nodes) {
|
|
|
|
if ($node =~ /[A-Z]/) {
|
|
|
|
$invalidnodename .= ",$node";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($invalidnodename) {
|
|
|
|
$invalidnodename =~ s/,//;
|
2010-03-30 04:13:18 +00:00
|
|
|
$callback->( {warning => "The node name \'$invalidnodename\' contains capital letters which may not be resolved correctly by the dns server."} );
|
2010-03-24 14:51:26 +00:00
|
|
|
}
|
2009-09-29 20:41:13 +00:00
|
|
|
} elsif ($groupmode) {
|
|
|
|
@groups = split /,/, shift @ARGV;
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
my $column;
|
|
|
|
my $value;
|
|
|
|
my $temp;
|
|
|
|
my %tables;
|
2008-09-07 20:43:03 +00:00
|
|
|
my %criteria=();
|
2008-02-06 15:21:54 +00:00
|
|
|
my $tab;
|
|
|
|
|
|
|
|
#print Dumper($deletemode);
|
2008-03-08 14:14:00 +00:00
|
|
|
foreach (@ARGV)
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
|
|
|
if ($deletemode)
|
|
|
|
{
|
2008-03-08 14:14:00 +00:00
|
|
|
if (m/[=\.]/) # in delete mode they can only specify tables names
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
2008-03-08 14:14:00 +00:00
|
|
|
$callback->({error => [". and = not valid in delete mode."],errorcode=>1});
|
2008-02-06 15:21:54 +00:00
|
|
|
next;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
$tables{$_} = 1;
|
|
|
|
next;
|
|
|
|
}
|
2008-09-07 20:43:03 +00:00
|
|
|
unless (m/=/ or m/!~/)
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
2008-03-08 14:14:00 +00:00
|
|
|
$callback->({error => ["Malformed argument $_ ignored."],errorcode=>1});
|
2008-02-06 15:21:54 +00:00
|
|
|
next;
|
|
|
|
}
|
2008-09-07 20:43:03 +00:00
|
|
|
my $stable;
|
|
|
|
my $scolumn;
|
|
|
|
#Check for selection criteria
|
|
|
|
if (m/^[^=]*==/) {
|
|
|
|
($temp,$value)=split /==/,$_,2;
|
|
|
|
($stable,$scolumn)=getTableColumn($temp);
|
|
|
|
$criteria{$stable}->{$scolumn}=[$value,'match'];
|
|
|
|
|
|
|
|
next; #Is a selection criteria, not an assignment specification
|
|
|
|
} elsif (m/^[^=]*!=/) {
|
|
|
|
($temp,$value)=split /!=/,$_,2;
|
|
|
|
($stable,$scolumn)=getTableColumn($temp);
|
|
|
|
$criteria{$stable}->{$scolumn}=[$value,'natch'];
|
|
|
|
next; #Is a selection criteria, not an assignment specification
|
|
|
|
} elsif (m/^[^=]*=~/) {
|
|
|
|
($temp,$value)=split /=~/,$_,2;
|
|
|
|
($stable,$scolumn)=getTableColumn($temp);
|
|
|
|
$value =~ s/^\///;
|
|
|
|
$value =~ s/\/$//;
|
|
|
|
$criteria{$stable}->{$scolumn}=[$value,'regex'];
|
|
|
|
next; #Is a selection criteria, not an assignment specification
|
|
|
|
} elsif (m/^[^=]*!~/) {
|
|
|
|
($temp,$value)=split /!~/,$_,2;
|
|
|
|
($stable,$scolumn)=getTableColumn($temp);
|
|
|
|
$value =~ s/^\///;
|
|
|
|
$value =~ s/\/$//;
|
|
|
|
$criteria{$stable}->{$scolumn}=[$value,'negex'];
|
|
|
|
next; #Is a selection criteria, not an assignment specification
|
|
|
|
}
|
|
|
|
#Now definitely an assignment
|
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
($temp, $value) = split('=', $_, 2);
|
2008-09-07 20:43:03 +00:00
|
|
|
$value =~ s/^@//; #Allow the =@ operator to exist for an unambiguous assignmenet operator
|
|
|
|
#So before, table.column==value meant set to =value, now it would be matching value
|
|
|
|
#the new way would be table.column=@=value to be unambiguous
|
|
|
|
#now a value like '@hi' would be set with table.column=@@hi
|
2008-12-09 15:23:12 +00:00
|
|
|
if ($value eq '') { #If blank, force a null entry to override group settings
|
|
|
|
$value = '|^.*$||';
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
my $op = '=';
|
|
|
|
if ($temp =~ /,$/)
|
|
|
|
{
|
|
|
|
$op = ',=';
|
|
|
|
chop($temp);
|
|
|
|
}
|
|
|
|
elsif ($temp =~ /\^$/)
|
|
|
|
{
|
|
|
|
$op = '^=';
|
|
|
|
chop($temp);
|
|
|
|
}
|
|
|
|
|
2008-07-18 19:37:43 +00:00
|
|
|
my $table;
|
2008-02-06 15:21:54 +00:00
|
|
|
if ($shortnames{$temp})
|
|
|
|
{
|
|
|
|
($table, $column) = @{$shortnames{$temp}};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
($table, $column) = split('\.', $temp, 2);
|
|
|
|
}
|
2008-03-03 21:00:13 +00:00
|
|
|
unless (grep /$column/,@{$xCAT::Schema::tabspec{$table}->{cols}}) {
|
|
|
|
$callback->({error=>"$table.$column not a valid table.column description",errorcode=>[1]});
|
|
|
|
return;
|
|
|
|
}
|
2008-03-08 14:14:00 +00:00
|
|
|
|
|
|
|
# Keep a list of the value/op pairs, in case there is more than 1 per table.column
|
|
|
|
#$tables{$table}->{$column} = [$value, $op];
|
|
|
|
push @{$tables{$table}->{$column}}, ($value, $op);
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
2008-09-07 20:43:03 +00:00
|
|
|
my %nodehash;
|
|
|
|
if (keys %criteria) {
|
|
|
|
foreach (@$nodes) {
|
|
|
|
$nodehash{$_}=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach $tab (keys %criteria) {
|
|
|
|
my $tabhdl = xCAT::Table->new($tab, -create => 1, -autocommit => 0);
|
|
|
|
my @columns=keys %{$criteria{$tab}};
|
|
|
|
my $tabhash = $tabhdl->getNodesAttribs($nodes,\@columns);
|
|
|
|
my $node;
|
|
|
|
my $col;
|
|
|
|
my $rec;
|
|
|
|
foreach $node (@$nodes) {
|
|
|
|
foreach $rec (@{$tabhash->{$node}}) {
|
|
|
|
foreach $col (@columns) {
|
|
|
|
my $value=$criteria{$tab}->{$col}->[0];
|
|
|
|
unless (defined $value) {
|
|
|
|
$value = "";
|
|
|
|
}
|
|
|
|
my $matchtype=$criteria{$tab}->{$col}->[1];
|
|
|
|
if ($matchtype eq 'match' and not ($rec->{$col} eq $value) or
|
|
|
|
$matchtype eq 'natch' and ($rec->{$col} eq $value) or
|
|
|
|
$matchtype eq 'regex' and ($rec->{$col} !~ /$value/) or
|
|
|
|
$matchtype eq 'negex' and ($rec->{$col} =~ /$value/)) {
|
|
|
|
delete $nodehash{$node};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$nodes = [keys %nodehash];
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
foreach $tab (keys %tables)
|
|
|
|
{
|
|
|
|
my $tabhdl = xCAT::Table->new($tab, -create => 1, -autocommit => 0);
|
|
|
|
if ($tabhdl)
|
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
my $changed=0;
|
2009-10-08 22:23:10 +00:00
|
|
|
my @entities;
|
|
|
|
if ($groupmode) {
|
|
|
|
@entities = @groups;
|
|
|
|
} else {
|
|
|
|
@entities = @$nodes;
|
2009-09-29 20:41:13 +00:00
|
|
|
}
|
2009-10-08 22:23:10 +00:00
|
|
|
my $entity;
|
|
|
|
foreach $entity (@entities) {
|
|
|
|
if ($deletemode) {
|
|
|
|
$tabhdl->delEntries({'node' => $entity});
|
2011-03-20 06:53:44 +00:00
|
|
|
$changed=1;
|
2009-10-08 22:23:10 +00:00
|
|
|
} else {
|
|
|
|
#$tabhdl->setNodeAttribs($_,$tables{$tab});
|
|
|
|
my %uhsh;
|
2011-03-20 06:53:44 +00:00
|
|
|
foreach (keys %{$tables{$tab}}) # for each column specified for this table
|
2009-10-08 22:23:10 +00:00
|
|
|
{
|
|
|
|
#my $op = $tables{$tab}->{$_}->[1];
|
|
|
|
#my $val = $tables{$tab}->{$_}->[0];
|
|
|
|
my @valoppairs = @{$tables{$tab}->{$_}}; #Deep copy
|
2011-03-20 06:53:44 +00:00
|
|
|
while (scalar(@valoppairs)) { # alternating list of value and op for this table.column
|
2009-10-08 22:23:10 +00:00
|
|
|
my $val = shift @valoppairs;
|
|
|
|
my $op = shift @valoppairs;
|
|
|
|
my $key = $_;
|
2009-09-29 20:41:13 +00:00
|
|
|
# When changing the groups of the node, check whether the new group
|
|
|
|
# is a dynamic group.
|
|
|
|
if (($key eq 'groups') && ($op eq '=')) {
|
2009-10-08 22:23:10 +00:00
|
|
|
if ($groupmode) {
|
|
|
|
$callback->({error => "Group membership is not changeable via nodegrpch",errorcode=>1});
|
|
|
|
return;
|
|
|
|
}
|
2009-09-29 20:41:13 +00:00
|
|
|
if (scalar(@grplist) == 0) { # Do not call $grptab->getAllEntries for each node, performance issue.
|
|
|
|
$grptab = xCAT::Table->new('nodegroup');
|
|
|
|
if ($grptab) {
|
|
|
|
@grplist = @{$grptab->getAllEntries()};
|
2009-06-02 05:29:55 +00:00
|
|
|
}
|
2009-09-29 20:41:13 +00:00
|
|
|
}
|
|
|
|
my @grps = split(/,/, $val);
|
|
|
|
foreach my $grp (@grps) {
|
|
|
|
foreach my $grpdef_ref (@grplist) {
|
|
|
|
my %grpdef = %$grpdef_ref;
|
|
|
|
if (($grpdef{'groupname'} eq $grp) && ($grpdef{'grouptype'} eq 'dynamic')) {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0] = "nodegroup $grp is a dynamic node group, should not add a node into a dynamic node group statically.\n";
|
|
|
|
$callback->(\%rsp);
|
2009-06-02 05:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-29 20:41:13 +00:00
|
|
|
}
|
2009-10-08 22:23:10 +00:00
|
|
|
if ($op eq '=') {
|
|
|
|
$uhsh{$key} = $val;
|
|
|
|
} elsif ($op eq ',=') { #splice assignment
|
|
|
|
if ($groupmode) {
|
|
|
|
$callback->({error => ",= and ^= are not supported by nodegrpch",errorcode=>1});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
my $curval = $uhsh{$key}; # in case it was already set
|
|
|
|
if (!defined($curval)) {
|
|
|
|
my $cent = $tabhdl->getNodeAttribs($entity, [$key]);
|
|
|
|
if ($cent) { $curval = $cent->{$key}; }
|
|
|
|
}
|
|
|
|
if ($curval) {
|
|
|
|
my @vals = split(/,/, $curval);
|
|
|
|
unless (grep /^$val$/, @vals) {
|
|
|
|
unshift @vals,$val;
|
|
|
|
my $newval = join(',', @vals);
|
|
|
|
$uhsh{$key} = $newval;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$uhsh{$key} = $val;
|
|
|
|
}
|
|
|
|
} elsif ($op eq '^=') {
|
|
|
|
if ($groupmode) {
|
|
|
|
$callback->({error => ",= and ^= are not supported by nodegrpch",errorcode=>1});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
my $curval = $uhsh{$key}; # in case it was already set
|
|
|
|
if (!defined($curval)) {
|
|
|
|
my $cent = $tabhdl->getNodeAttribs($entity, [$key]);
|
|
|
|
if ($cent) { $curval = $cent->{$key}; }
|
|
|
|
}
|
|
|
|
if ($curval) {
|
|
|
|
my @vals = split(/,/, $curval);
|
|
|
|
if (grep /^$val$/, @vals) { #only bother if there
|
|
|
|
@vals = grep(!/^$val$/, @vals);
|
|
|
|
my $newval = join(',', @vals);
|
|
|
|
$uhsh{$key} = $newval;
|
|
|
|
}
|
|
|
|
} #else, what they asked for is the case alredy
|
|
|
|
}
|
2011-03-20 06:53:44 +00:00
|
|
|
} # end of while @valoppairs
|
|
|
|
} # end of foreach column specified for this table
|
2009-10-08 22:23:10 +00:00
|
|
|
|
|
|
|
if (keys %uhsh)
|
|
|
|
{
|
|
|
|
if ($groupmode) {
|
|
|
|
my $nodekey = "node";
|
|
|
|
if (defined $xCAT::Schema::tabspec{$tab}->{nodecol}) {
|
|
|
|
$nodekey = $xCAT::Schema::tabspec{$tab}->{nodecol}
|
|
|
|
}
|
|
|
|
my %clrhash; #First, we prepare to clear all nodes of their overrides on these columns
|
|
|
|
foreach (keys %uhsh) {
|
|
|
|
if ($_ eq $nodekey) { next; } #skip attempts to manipulate 'node' type columns in a groupch
|
|
|
|
$clrhash{$_}="";
|
|
|
|
}
|
2012-06-18 16:34:42 +00:00
|
|
|
$tabhdl->setAttribs({$nodekey=>$entity},\%uhsh);
|
2011-03-20 06:53:44 +00:00
|
|
|
$changed=1;
|
2009-10-08 22:23:10 +00:00
|
|
|
$nodes = [noderange($entity)];
|
2009-09-29 20:41:13 +00:00
|
|
|
unless (scalar @$nodes) { next; }
|
|
|
|
$tabhdl->setNodesAttribs($nodes,\%clrhash);
|
2011-03-20 06:53:44 +00:00
|
|
|
$changed=1;
|
2009-10-08 22:23:10 +00:00
|
|
|
} else {
|
|
|
|
my @rc = $tabhdl->setNodeAttribs($entity, \%uhsh);
|
2011-03-20 06:53:44 +00:00
|
|
|
$changed=1;
|
2009-10-08 22:23:10 +00:00
|
|
|
if (not defined($rc[0])) {
|
|
|
|
$callback->({error => "DB error " . $rc[1],errorcode=>1});
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-20 19:20:46 +00:00
|
|
|
}
|
2011-03-20 06:53:44 +00:00
|
|
|
if ($changed) {
|
|
|
|
$tabhdl->commit;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$callback->(
|
2008-03-08 14:14:00 +00:00
|
|
|
{error => ["ERROR: Unable to open table $tab in configuration"],errorcode=>1}
|
2008-02-06 15:21:54 +00:00
|
|
|
);
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-05 05:12:38 +00:00
|
|
|
# gennr linked to xcatclientnnr and is used to generate a list of nodes
|
|
|
|
# external to the database.
|
|
|
|
sub gennr {
|
2011-03-20 06:53:44 +00:00
|
|
|
my $nodes = shift;
|
|
|
|
my $args = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
@ARGV = @{$args};
|
|
|
|
my $nr = shift @ARGV;
|
|
|
|
$nodes = [noderange($nr, 0)];
|
|
|
|
my %rsp; # for output.
|
|
|
|
foreach (@$nodes){
|
|
|
|
#print $_ . "\n";
|
|
|
|
push @{$rsp{data}}, $_;
|
|
|
|
|
|
|
|
}
|
|
|
|
$callback->(\%rsp);
|
2010-01-05 05:12:38 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
sub tabgrep
|
|
|
|
{
|
|
|
|
my $node = shift;
|
|
|
|
my @tablist;
|
|
|
|
my $callback = shift;
|
2008-01-18 16:47:26 +00:00
|
|
|
|
2009-08-26 19:41:30 +00:00
|
|
|
if (!defined($node) || !scalar(@$node)) {
|
|
|
|
my %rsp;
|
|
|
|
push @{$rsp{data}}, "Usage: tabgrep nodename";
|
|
|
|
push @{$rsp{data}}, " tabgrep [-?|-h|--help]";
|
|
|
|
$rsp{errorcode} = 1;
|
|
|
|
$callback->(\%rsp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
foreach (keys %{xCAT::Schema::tabspec})
|
|
|
|
{
|
|
|
|
if (grep /^node$/, @{$xCAT::Schema::tabspec{$_}->{cols}})
|
|
|
|
{
|
|
|
|
push @tablist, $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (@tablist)
|
|
|
|
{
|
|
|
|
my $tab = xCAT::Table->new($_);
|
2008-03-05 19:04:11 +00:00
|
|
|
unless ($tab) { next; }
|
2008-03-05 19:02:27 +00:00
|
|
|
if ($tab and $tab->getNodeAttribs($node->[0], ["node"]))
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
|
|
|
$callback->({data => [$_]});
|
|
|
|
}
|
|
|
|
$tab->close;
|
2008-01-18 16:47:26 +00:00
|
|
|
}
|
2008-01-21 19:39:09 +00:00
|
|
|
|
2008-01-18 16:47:26 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2009-04-14 18:27:43 +00:00
|
|
|
sub rnoderange
|
|
|
|
{
|
|
|
|
my $nodes = shift;
|
|
|
|
my $args = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $data = abbreviate_noderange($nodes);
|
|
|
|
if ($data) {
|
|
|
|
$callback->({data=>[$data]});
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
#####################################################
|
|
|
|
# nodels command
|
|
|
|
#####################################################
|
2008-02-06 15:21:54 +00:00
|
|
|
sub nodels
|
|
|
|
{
|
|
|
|
my $nodes = shift;
|
|
|
|
my $args = shift;
|
|
|
|
my $callback = shift;
|
|
|
|
my $noderange = shift;
|
2008-07-18 19:37:43 +00:00
|
|
|
unless ($nodes) {
|
|
|
|
$nodes=[];
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
|
|
|
|
my $VERSION;
|
|
|
|
my $HELP;
|
|
|
|
|
2008-07-18 22:36:32 +00:00
|
|
|
my $nodels_usage = sub
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
my $exitcode = shift @_;
|
2008-02-06 15:21:54 +00:00
|
|
|
my %rsp;
|
2008-03-08 14:14:00 +00:00
|
|
|
push @{$rsp{data}}, "Usage:";
|
2011-01-18 14:18:55 +00:00
|
|
|
push @{$rsp{data}}, " nodels [noderange] [-b|--blame] [-H|--with-fieldname] [table.attribute | shortname] [-S][...]";
|
2008-03-08 14:14:00 +00:00
|
|
|
push @{$rsp{data}}, " nodels {-v|--version}";
|
|
|
|
push @{$rsp{data}}, " nodels [-?|-h|--help]";
|
|
|
|
if ($exitcode) { $rsp{errorcode} = $exitcode; }
|
|
|
|
$callback->(\%rsp);
|
2008-07-18 22:36:32 +00:00
|
|
|
};
|
2008-02-06 15:21:54 +00:00
|
|
|
|
2008-07-18 19:37:43 +00:00
|
|
|
if ($args) {
|
|
|
|
@ARGV = @{$args};
|
|
|
|
} else {
|
|
|
|
@ARGV=();
|
|
|
|
}
|
2008-05-19 17:59:56 +00:00
|
|
|
my $NOTERSE;
|
2010-03-05 22:28:36 +00:00
|
|
|
my $ATTRIBUTION;
|
2011-01-18 14:18:55 +00:00
|
|
|
my $HIDDEN;
|
2008-10-31 12:16:28 +00:00
|
|
|
|
2011-01-18 14:18:55 +00:00
|
|
|
if (!GetOptions('h|?|help' => \$HELP, 'H|with-fieldname' => \$NOTERSE, 'b|blame' => \$ATTRIBUTION, 'v|version' => \$VERSION, 'S' => \$HIDDEN) ) { $nodels_usage->(1); return; }
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
# Help
|
2008-10-31 12:16:28 +00:00
|
|
|
if ($HELP) { $nodels_usage->(0); return; }
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
# Version
|
|
|
|
if ($VERSION)
|
|
|
|
{
|
|
|
|
my %rsp;
|
2008-07-07 18:29:55 +00:00
|
|
|
my $version = xCAT::Utils->Version();
|
2008-07-18 19:37:43 +00:00
|
|
|
$rsp{data}->[0] = "$version";
|
|
|
|
$callback->(\%rsp);
|
2008-02-06 15:21:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# TODO -- Parse command arguments
|
|
|
|
# my $opt;
|
|
|
|
# my %attrs;
|
|
|
|
# foreach $opt (@ARGV) {
|
|
|
|
# if ($opt =~ /^group/) {
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
my $argc = @ARGV;
|
2008-05-16 21:14:09 +00:00
|
|
|
my $terse = 2;
|
2008-05-19 17:59:56 +00:00
|
|
|
if ($NOTERSE) {
|
|
|
|
$terse = 0;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
|
|
|
|
if (@$nodes > 0 or $noderange)
|
|
|
|
{ #Make sure that there are zero nodes *and* that a noderange wasn't requested
|
|
|
|
# TODO - gather data for each node
|
|
|
|
# for now just return the flattened list of nodes)
|
2008-07-18 19:37:43 +00:00
|
|
|
my $rsp; #build up fewer requests, be less chatty
|
2011-03-20 06:56:10 +00:00
|
|
|
|
|
|
|
#-S will make nodels not show FSPs and BPAs
|
|
|
|
my @newnodes = ();
|
|
|
|
if (!defined($HIDDEN))
|
|
|
|
{
|
|
|
|
my $listtab = xCAT::Table->new( 'nodelist' );
|
|
|
|
if ($listtab) {
|
|
|
|
my $listHash = $listtab->getNodesAttribs(\@$nodes, ['hidden']);
|
|
|
|
foreach my $rnode(@$nodes) {
|
|
|
|
unless (defined($listHash->{$rnode}->[0]->{hidden})){
|
|
|
|
push (@newnodes, $rnode);
|
|
|
|
} elsif ($listHash->{$rnode}->[0]->{hidden} ne 1) {
|
|
|
|
push (@newnodes, $rnode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$nodes = \@newnodes;
|
|
|
|
}
|
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
if ($argc)
|
|
|
|
{
|
|
|
|
my %tables;
|
|
|
|
foreach (@ARGV)
|
|
|
|
{
|
|
|
|
my $table;
|
|
|
|
my $column;
|
2008-09-07 16:31:56 +00:00
|
|
|
my $value;
|
|
|
|
my $matchtype;
|
2008-02-06 15:21:54 +00:00
|
|
|
my $temp = $_;
|
2008-09-07 16:31:56 +00:00
|
|
|
if ($temp =~ /^[^=]*\!=/) {
|
|
|
|
($temp,$value) = split /!=/,$temp,2;
|
|
|
|
$matchtype='natch';
|
|
|
|
}
|
|
|
|
elsif ($temp =~ /^[^=]*=~/) {
|
|
|
|
($temp,$value) = split /=~/,$temp,2;
|
2008-09-07 16:33:47 +00:00
|
|
|
$value =~ s/^\///;
|
|
|
|
$value =~ s/\/$//;
|
2008-09-07 16:31:56 +00:00
|
|
|
$matchtype='regex';
|
|
|
|
}
|
|
|
|
elsif ($temp =~ /[^=]*==/) {
|
|
|
|
($temp,$value) = split /==/,$temp,2;
|
|
|
|
$matchtype='match';
|
|
|
|
}
|
|
|
|
elsif ($temp =~ /[^=]*!~/) {
|
|
|
|
($temp,$value) = split /!~/,$temp,2;
|
2008-09-07 16:33:47 +00:00
|
|
|
$value =~ s/^\///;
|
|
|
|
$value =~ s/\/$//;
|
2008-09-07 16:31:56 +00:00
|
|
|
$matchtype='negex';
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
if ($shortnames{$temp})
|
|
|
|
{
|
|
|
|
($table, $column) = @{$shortnames{$temp}};
|
2008-05-16 21:14:09 +00:00
|
|
|
$terse--;
|
2008-04-22 14:29:14 +00:00
|
|
|
} elsif ($temp =~ /\./) {
|
2008-02-06 15:21:54 +00:00
|
|
|
($table, $column) = split('\.', $temp, 2);
|
2008-05-16 21:14:09 +00:00
|
|
|
$terse--;
|
2008-04-22 14:29:14 +00:00
|
|
|
} elsif ($xCAT::Schema::tabspec{$temp}) {
|
2008-05-16 21:14:09 +00:00
|
|
|
$terse=0;
|
2008-04-22 14:29:14 +00:00
|
|
|
$table = $temp;
|
|
|
|
foreach my $column (@{$xCAT::Schema::tabspec{$table}->{cols}}) {
|
|
|
|
unless (grep /^$column$/, @{$tables{$table}}) {
|
|
|
|
push @{$tables{$table}},[$column,"$temp.$column"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next;
|
|
|
|
} else {
|
|
|
|
$callback->({error=>"$temp not a valid table.column description",errorcode=>[1]});
|
|
|
|
next;
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
2008-04-22 14:29:14 +00:00
|
|
|
|
|
|
|
|
2008-03-03 21:00:13 +00:00
|
|
|
unless (grep /$column/,@{$xCAT::Schema::tabspec{$table}->{cols}}) {
|
|
|
|
$callback->({error=>"$table.$column not a valid table.column description",errorcode=>[1]});
|
|
|
|
next;
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
unless (grep /^$column$/, @{$tables{$table}})
|
|
|
|
{
|
|
|
|
push @{$tables{$table}},
|
2008-09-07 16:31:56 +00:00
|
|
|
[$column, $temp,$value,$matchtype]; #Mark this as something to get
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
my $tab;
|
|
|
|
my %noderecs;
|
2008-09-07 16:31:56 +00:00
|
|
|
my %filterednodes=();
|
|
|
|
my %mustdisplaynodes=();
|
|
|
|
my %forcedisplaykeys=();
|
2008-02-06 15:21:54 +00:00
|
|
|
foreach $tab (keys %tables)
|
|
|
|
{
|
|
|
|
my $tabh = xCAT::Table->new($tab);
|
|
|
|
unless ($tabh) { next; }
|
|
|
|
|
|
|
|
#print Dumper($tables{$tab});
|
|
|
|
my $node;
|
2008-07-18 19:25:15 +00:00
|
|
|
my %labels;
|
2008-09-07 16:31:56 +00:00
|
|
|
my %values;
|
|
|
|
my %matchtypes;
|
2008-07-18 19:37:43 +00:00
|
|
|
my @cols=();
|
2008-09-07 16:31:56 +00:00
|
|
|
foreach (@{$tables{$tab}})
|
2008-07-18 19:25:15 +00:00
|
|
|
{
|
|
|
|
push @cols, $_->[0];
|
2008-09-07 16:31:56 +00:00
|
|
|
$labels{$_->[0]} = $_->[1]; #Remember user supplied discreptions and use them
|
|
|
|
if (not defined $values{$_->[0]}) { #If selection criteria not previously specified
|
|
|
|
$values{$_->[0]} = $_->[2]; #assign selection criteria
|
|
|
|
} elsif (not defined $_->[2]) { #we already have selection criteria, but this field isn't that
|
|
|
|
$forcedisplaykeys{$_->[0]}=1; #allow switch.switch=~switch switch.switch, for example
|
|
|
|
} else { #User attempted multiple selection criteria on the same field, bail
|
|
|
|
$callback->({error=>["Multiple selection critera for ".$labels{$_->[0]}]});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (not defined $matchtypes{$_->[0]}) {
|
|
|
|
$matchtypes{$_->[0]} = $_->[3];
|
|
|
|
}
|
2008-07-18 19:25:15 +00:00
|
|
|
}
|
2009-09-17 18:27:07 +00:00
|
|
|
my $nodekey = "node";
|
|
|
|
if (defined $xCAT::Schema::tabspec{$tab}->{nodecol}) {
|
|
|
|
$nodekey = $xCAT::Schema::tabspec{$tab}->{nodecol}
|
|
|
|
};
|
|
|
|
|
2008-07-18 19:25:15 +00:00
|
|
|
my $removenodecol=1;
|
2009-09-17 18:27:07 +00:00
|
|
|
if (grep /^$nodekey$/,@cols) {
|
2008-07-18 19:25:15 +00:00
|
|
|
$removenodecol=0;
|
|
|
|
}
|
2010-03-05 22:28:36 +00:00
|
|
|
my $rechash=$tabh->getNodesAttribs($nodes,\@cols,withattribution=>$ATTRIBUTION);
|
2008-02-06 15:21:54 +00:00
|
|
|
foreach $node (@$nodes)
|
|
|
|
{
|
|
|
|
my @cols;
|
2008-07-18 19:25:15 +00:00
|
|
|
my $recs = $rechash->{$node}; #$tabh->getNodeAttribs($node, \@cols);
|
2008-09-07 16:31:56 +00:00
|
|
|
my %satisfiedreqs=();
|
2008-07-18 19:25:15 +00:00
|
|
|
foreach my $rec (@$recs) {
|
|
|
|
|
|
|
|
foreach (keys %$rec)
|
|
|
|
{
|
2010-03-05 22:28:36 +00:00
|
|
|
if ($_ eq '!!xcatgroupattribution!!') { next; }
|
2009-09-17 18:27:07 +00:00
|
|
|
if ($_ eq $nodekey and $removenodecol) { next; }
|
2008-09-07 16:31:56 +00:00
|
|
|
$satisfiedreqs{$_}=1;
|
|
|
|
my %datseg=();
|
|
|
|
if (defined $values{$_}) {
|
|
|
|
my $criteria=$values{$_}; #At least vim highlighting makes me worry about syntax in regex
|
|
|
|
if ($matchtypes{$_} eq 'match' and not ($rec->{$_} eq $criteria) or
|
|
|
|
$matchtypes{$_} eq 'natch' and ($rec->{$_} eq $criteria) or
|
|
|
|
$matchtypes{$_} eq 'regex' and ($rec->{$_} !~ /$criteria/) or
|
|
|
|
$matchtypes{$_} eq 'negex' and ($rec->{$_} =~ /$criteria/)) {
|
|
|
|
#unless ($rec->{$_} eq $values{$_}) {
|
|
|
|
$filterednodes{$node}=1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$mustdisplaynodes{$node}=1;
|
|
|
|
unless ($forcedisplaykeys{$_}) { next; } #skip if only specified once on command line
|
|
|
|
}
|
|
|
|
unless ($terse > 0) {
|
|
|
|
$datseg{data}->[0]->{desc} = [$labels{$_}];
|
|
|
|
}
|
2010-03-05 22:28:36 +00:00
|
|
|
if ($rec->{'!!xcatgroupattribution!!'} and $rec->{'!!xcatgroupattribution!!'}->{$_}) {
|
|
|
|
$datseg{data}->[0]->{contents} = [$rec->{$_}." (inherited from group ".$rec->{'!!xcatgroupattribution!!'}->{$_}.")"];
|
|
|
|
} else {
|
|
|
|
$datseg{data}->[0]->{contents} = [$rec->{$_}];
|
|
|
|
}
|
2008-09-07 16:31:56 +00:00
|
|
|
$datseg{name} = [$node]; #{}->{contents} = [$rec->{$_}];
|
|
|
|
push @{$noderecs{$node}}, \%datseg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (keys %labels) {
|
|
|
|
unless (defined $satisfiedreqs{$_}) {
|
|
|
|
my %dataseg;
|
|
|
|
if (defined $values{$_}) {
|
|
|
|
my $criteria = $values{$_};
|
|
|
|
if ($matchtypes{$_} eq 'match' and not ("" eq $criteria) or
|
|
|
|
$matchtypes{$_} eq 'natch' and ("" eq $criteria) or
|
|
|
|
$matchtypes{$_} eq 'regex' and ("" !~ /$criteria/) or
|
|
|
|
$matchtypes{$_} eq 'negex' and ("" =~ /$criteria/)) {
|
|
|
|
#unless ("" eq $values{$_}) {
|
|
|
|
$filterednodes{$node}=1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$mustdisplaynodes{$node}=1;
|
|
|
|
unless ($forcedisplaykeys{$_}) { next; }
|
|
|
|
}
|
|
|
|
$dataseg{name} = [ $node ];
|
|
|
|
unless ($terse > 0) {
|
|
|
|
$dataseg{data}->[0]->{desc} = [$labels{$_}];
|
|
|
|
}
|
|
|
|
$dataseg{data}->[0]->{contents} = [""];
|
|
|
|
push @{$noderecs{$node}}, \%dataseg;
|
2008-05-16 21:14:09 +00:00
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#$rsp->{node}->[0]->{data}->[0]->{desc}->[0] = $_;
|
|
|
|
#$rsp->{node}->[0]->{data}->[0]->{contents}->[0] = $_;
|
|
|
|
$tabh->close();
|
|
|
|
undef $tabh;
|
|
|
|
}
|
2008-09-07 16:31:56 +00:00
|
|
|
foreach (keys %mustdisplaynodes) {
|
|
|
|
if ($filterednodes{$_} or defined $noderecs{$_}) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$noderecs{$_}=[{name=>[$_]}];
|
|
|
|
}
|
|
|
|
foreach (keys %filterednodes) {
|
|
|
|
delete $noderecs{$_};
|
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
foreach (sort (keys %noderecs))
|
|
|
|
{
|
|
|
|
push @{$rsp->{"node"}}, @{$noderecs{$_}};
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2008-02-06 15:21:54 +00:00
|
|
|
else
|
|
|
|
{
|
2010-02-08 04:30:01 +00:00
|
|
|
foreach (sort @$nodes)
|
2008-02-06 15:21:54 +00:00
|
|
|
{
|
|
|
|
my $noderec;
|
|
|
|
$noderec->{name}->[0] = ($_);
|
|
|
|
push @{$rsp->{node}}, $noderec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$callback->($rsp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
# no noderange specified on command line, return list of all nodes
|
|
|
|
my $nodelisttab;
|
|
|
|
if ($nodelisttab = xCAT::Table->new("nodelist"))
|
|
|
|
{
|
|
|
|
my @attribs = ("node");
|
|
|
|
my @ents = $nodelisttab->getAllAttribs(@attribs);
|
2011-03-20 06:53:44 +00:00
|
|
|
my @nodes;
|
2010-01-29 08:23:22 +00:00
|
|
|
foreach (@ents) {
|
2011-03-20 06:53:44 +00:00
|
|
|
if ($_->{node}) {
|
|
|
|
push @nodes, $_->{node};
|
|
|
|
}
|
|
|
|
}
|
2011-01-18 14:18:55 +00:00
|
|
|
#-S will make nodels not show FSPs and BPAs
|
|
|
|
my @newnodes = ();
|
2011-01-18 15:14:54 +00:00
|
|
|
if (!defined($HIDDEN))
|
2011-01-18 14:18:55 +00:00
|
|
|
{
|
|
|
|
my $listtab = xCAT::Table->new( 'nodelist' );
|
|
|
|
if ($listtab) {
|
|
|
|
my $listHash = $listtab->getNodesAttribs(\@nodes, ['hidden']);
|
|
|
|
foreach my $rnode(@nodes) {
|
|
|
|
unless (defined($listHash->{$rnode}->[0]->{hidden})){
|
|
|
|
push (@newnodes, $rnode);
|
|
|
|
} elsif ($listHash->{$rnode}->[0]->{hidden} ne 1) {
|
|
|
|
push (@newnodes, $rnode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@nodes = ();
|
|
|
|
foreach (@newnodes) {
|
|
|
|
push (@nodes, $_);
|
|
|
|
}
|
|
|
|
}
|
2011-03-20 06:53:44 +00:00
|
|
|
@nodes = sort {$a cmp $b} @nodes;
|
|
|
|
foreach (@nodes) {
|
2008-07-18 19:37:43 +00:00
|
|
|
my $rsp;
|
2010-01-29 08:23:22 +00:00
|
|
|
#if ($_)
|
|
|
|
#{
|
|
|
|
$rsp->{node}->[0]->{name}->[0] = ($_);
|
2008-02-06 15:21:54 +00:00
|
|
|
|
|
|
|
# $rsp->{node}->[0]->{data}->[0]->{contents}->[0]="$_->{node} node contents";
|
|
|
|
# $rsp->{node}->[0]->{data}->[0]->{desc}->[0]="$_->{node} node desc";
|
|
|
|
$callback->($rsp);
|
2010-01-29 08:23:22 +00:00
|
|
|
#}
|
2008-02-06 15:21:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-06 15:21:54 +00:00
|
|
|
return 0;
|
2007-10-26 22:44:33 +00:00
|
|
|
}
|
2010-02-03 22:06:43 +00:00
|
|
|
|
|
|
|
#########
|
|
|
|
# tabch
|
|
|
|
#########
|
2010-02-04 06:03:24 +00:00
|
|
|
|
2010-02-03 22:06:43 +00:00
|
|
|
sub tabch {
|
2011-09-07 15:20:00 +00:00
|
|
|
my $req = shift;
|
2011-03-20 06:53:44 +00:00
|
|
|
my $callback = shift;
|
2011-09-07 15:20:00 +00:00
|
|
|
|
|
|
|
# tabch usages message
|
|
|
|
my $tabch_usage = sub {
|
|
|
|
my $exitcode = shift @_;
|
|
|
|
my %rsp;
|
|
|
|
push @{$rsp{data}}, "Usage: tabch";
|
|
|
|
push @{$rsp{data}}, " To add or update rows for tables:";
|
2012-04-04 14:59:07 +00:00
|
|
|
push @{$rsp{data}}, " tabch [keycolname=keyvalue[,keycolname=keyvalue...]] [tablename.colname=newvalue] [tablename.colname=newvalue]...";
|
2011-09-07 15:20:00 +00:00
|
|
|
push @{$rsp{data}}, " To delete rows from tables:";
|
2012-04-04 14:59:07 +00:00
|
|
|
push @{$rsp{data}}, " tabch -d|--delete keycolname=keyvalue[,keycolname=keyvalue...] tablename [tablename]...";
|
|
|
|
push @{$rsp{data}}, " keycolname=keyvalue a column name-and-value pair ";
|
|
|
|
push @{$rsp{data}}, " that identifies the rows in a table to be changed.";
|
|
|
|
push @{$rsp{data}}, " a column name-and-value pair that identifies ";
|
|
|
|
push @{$rsp{data}}, " the rows in a table to be changed.";
|
|
|
|
push @{$rsp{data}}, " that identifies the rows in a table to be changed.";
|
|
|
|
push @{$rsp{data}}, " tablename.colname=newvalue ";
|
|
|
|
push @{$rsp{data}}, " the new value for the specified row and column of the table.";
|
2012-05-25 10:39:49 +00:00
|
|
|
push @{$rsp{data}}, " tabch [-h|--help]";
|
|
|
|
push @{$rsp{data}}, " tabch [-v|--version]";
|
2011-09-07 15:20:00 +00:00
|
|
|
if ($exitcode) { $rsp{errorcode} = $exitcode; }
|
|
|
|
$callback->(\%rsp);
|
|
|
|
};
|
|
|
|
|
|
|
|
# check for parameters
|
|
|
|
if (!defined($req->{arg})) { $tabch_usage->(1); return; }
|
|
|
|
@ARGV = @{$req->{arg}};
|
|
|
|
|
|
|
|
# options can be bundled up like -vV
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
$Getopt::Long::ignorecase = 0;
|
2012-04-22 10:17:43 +00:00
|
|
|
my $delete;
|
|
|
|
my $help;
|
|
|
|
my $version;
|
2011-09-07 15:20:00 +00:00
|
|
|
# parse the options
|
|
|
|
if (
|
|
|
|
!GetOptions(
|
2012-04-22 10:17:43 +00:00
|
|
|
'd|delete' => \$delete,
|
|
|
|
'h|help' => \$help,
|
|
|
|
'v|version' => \$version,
|
2011-09-07 15:20:00 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
$tabch_usage->(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-22 10:17:43 +00:00
|
|
|
if ($help) { $tabch_usage->(0); return; }
|
2011-09-07 15:20:00 +00:00
|
|
|
|
|
|
|
# display the version statement if -v or --verison is specified
|
2012-04-22 10:17:43 +00:00
|
|
|
if ($version)
|
2011-09-07 15:20:00 +00:00
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
$rsp{data}->[0] = "tabch :$version";
|
|
|
|
$callback->(\%rsp);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
# now start processing the input
|
|
|
|
|
|
|
|
my $target = shift @ARGV;
|
|
|
|
unless ($target)
|
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
|
2011-09-07 15:20:00 +00:00
|
|
|
$tabch_usage->(1); return;
|
|
|
|
}
|
|
|
|
my %tables;
|
|
|
|
my %keyhash = ();
|
|
|
|
my @keypairs = split(/,/, $target);
|
|
|
|
if ($keypairs[0] !~ /([^\.\=]+)\.([^\.\=]+)\=(.+)/)
|
|
|
|
{
|
|
|
|
foreach (@keypairs)
|
|
|
|
{
|
|
|
|
m/(.*)=(.*)/;
|
|
|
|
my $key = $1;
|
|
|
|
my $val = $2;
|
|
|
|
if (!defined($key) || !defined($val))
|
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0] = "Incorrect argument \"$_\".\n";
|
|
|
|
$rsp{data}->[1] = "Check man tabch or tabch -h\n";
|
|
|
|
$callback->(\%rsp);
|
|
|
|
return 1;
|
2011-03-20 06:53:44 +00:00
|
|
|
}
|
2011-09-07 15:20:00 +00:00
|
|
|
$keyhash{$key} = $val;
|
2011-03-20 06:53:44 +00:00
|
|
|
}
|
2011-09-07 15:20:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unshift(@ARGV, $target);
|
|
|
|
}
|
2011-03-20 06:53:44 +00:00
|
|
|
|
2012-04-22 10:17:43 +00:00
|
|
|
if ($delete)
|
2011-09-07 15:20:00 +00:00
|
|
|
{
|
2011-03-20 06:53:44 +00:00
|
|
|
|
2011-09-07 15:20:00 +00:00
|
|
|
#delete option is specified
|
|
|
|
my @tables_to_del = @ARGV;
|
|
|
|
if (@tables_to_del == 0)
|
|
|
|
{
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0] = "Missing table name.\n";
|
|
|
|
$rsp{data}->[1] = "Check man tabch or tabch -h\n";
|
|
|
|
$callback->(\%rsp);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
for (@tables_to_del)
|
|
|
|
{
|
|
|
|
$tables{$_} = xCAT::Table->new($_, -create => 1, -autocommit => 0);
|
|
|
|
$tables{$_}->delEntries(\%keyhash);
|
|
|
|
$tables{$_}->commit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#update or create option
|
|
|
|
my %tableupdates;
|
|
|
|
for (@ARGV) {
|
|
|
|
my $temp;
|
|
|
|
my $table;
|
|
|
|
my $column;
|
|
|
|
my $value;
|
|
|
|
|
|
|
|
($table,$temp) = split('\.',$_,2);
|
|
|
|
|
|
|
|
#try to create the entry if it doesn't exist
|
|
|
|
unless ($tables{$table}) {
|
|
|
|
my $tab = xCAT::Table->new($table,-create => 1,-autocommit => 0);
|
|
|
|
if ($tab) {
|
|
|
|
$tables{$table}=$tab;
|
|
|
|
} else {
|
|
|
|
my %rsp;
|
|
|
|
$rsp{data}->[0] = "Table $table does not exist.\n";
|
|
|
|
$callback->(\%rsp);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#splice assignment
|
|
|
|
if(grep /\+=/, $temp) {
|
|
|
|
($column,$value) = split('\+=',$temp,2);
|
|
|
|
|
|
|
|
#grab the current values to check against
|
|
|
|
my ($attrHash) = $tables{$table}->getAttribs(\%keyhash, $column);
|
|
|
|
my @existing = split(",",$attrHash->{$column});
|
|
|
|
|
|
|
|
#if it has values, merge the new and old ones together so no dupes
|
|
|
|
if (@existing) {
|
|
|
|
my @values = split(",",$value);
|
|
|
|
my %seen = ();
|
|
|
|
my @uniq = ();
|
|
|
|
my $item;
|
|
|
|
|
|
|
|
foreach $item (@existing,@values) {
|
|
|
|
unless ($seen{$item}) {
|
|
|
|
# if we get here, we have not seen it before
|
|
|
|
$seen{$item} = 1;
|
|
|
|
push(@uniq, $item);
|
|
|
|
}
|
2011-03-20 06:53:44 +00:00
|
|
|
}
|
2011-09-07 15:20:00 +00:00
|
|
|
$value = join(",",@uniq);
|
2011-03-20 06:53:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-07 15:20:00 +00:00
|
|
|
#normal non-splicing assignment
|
|
|
|
else {
|
|
|
|
($column,$value) = split("=",$temp,2);
|
2011-03-20 06:53:44 +00:00
|
|
|
}
|
2012-04-22 18:57:50 +00:00
|
|
|
unless (grep /$column/,@{$xCAT::Schema::tabspec{$table}->{cols}}) {
|
|
|
|
$callback->({error=>"$table.$column not a valid table.column description",errorcode=>[1]});
|
|
|
|
return;
|
|
|
|
}
|
2011-09-07 15:20:00 +00:00
|
|
|
$tableupdates{$table}{$column}=$value;
|
|
|
|
}
|
|
|
|
|
|
|
|
#commit all the changes
|
2013-09-19 17:04:40 +00:00
|
|
|
my $rollback;
|
2011-09-07 15:20:00 +00:00
|
|
|
foreach (keys %tables) {
|
|
|
|
if (exists($tableupdates{$_})) {
|
2013-09-19 17:04:40 +00:00
|
|
|
my @rc=$tables{$_}->setAttribs(\%keyhash,\%{$tableupdates{$_}});
|
|
|
|
if (not defined($rc[0]))
|
|
|
|
{
|
|
|
|
$rollback = 1;
|
|
|
|
$callback->({error => "DB error " . $rc[1] , errorcode=>[4]});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($rollback)
|
|
|
|
{
|
|
|
|
$tables{$_}->rollback();
|
|
|
|
$tables{$_}->close;
|
|
|
|
undef $tables{$_};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$tables{$_}->commit;
|
2011-03-20 06:53:44 +00:00
|
|
|
}
|
2011-09-07 15:20:00 +00:00
|
|
|
}
|
|
|
|
}
|
2010-02-03 22:06:43 +00:00
|
|
|
}
|
2012-04-23 12:32:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# getAllEntries
|
|
|
|
#
|
|
|
|
# Read all the rows from the input table name and returns the response, so
|
|
|
|
# that the XML will look like this
|
2012-05-16 17:34:18 +00:00
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
|
|
|
#<command>getAllEntries</command>
|
|
|
|
#<table>nodelist</table>
|
|
|
|
#</xcatrequest>
|
|
|
|
|
|
|
|
|
2012-04-23 12:32:58 +00:00
|
|
|
#<xcatresponse>
|
2012-05-16 17:34:18 +00:00
|
|
|
#<row>
|
2012-04-23 12:32:58 +00:00
|
|
|
#<attr1>value1</attr1>
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#<attrN>valueN</attrN>
|
2012-05-16 17:34:18 +00:00
|
|
|
#</row>
|
2012-04-23 12:32:58 +00:00
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#</xcatresponse>
|
|
|
|
#
|
|
|
|
#
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-09-14 13:25:54 +00:00
|
|
|
my %noderecs;
|
|
|
|
foreach my $rec (@$recs) {
|
2012-04-23 12:32:58 +00:00
|
|
|
my %datseg=();
|
|
|
|
foreach my $key (keys %$rec) {
|
|
|
|
$datseg{$key} = $rec->{$key};
|
|
|
|
}
|
|
|
|
push @{$noderecs{"row"}}, \%datseg;
|
2012-09-14 13:25:54 +00:00
|
|
|
}
|
|
|
|
push @{$rsp{"row"}}, @{$noderecs{"row"}};
|
|
|
|
# for checkin XML created
|
|
|
|
#my $xmlrec=XMLout(\%rsp,RootName=>'xcatresponse',NoAttr=>1,KeyAttr=>[]);
|
|
|
|
$cb->(\%rsp);
|
2012-04-23 12:32:58 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
# getNodesAttribs
|
2012-09-12 13:45:34 +00:00
|
|
|
# Read the array of attributes for the noderange from the input table.
|
2012-05-16 16:25:49 +00:00
|
|
|
# If the <attr>ALL</attr> is input then read all the attributes
|
2012-05-14 19:28:17 +00:00
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
|
|
|
#<command>getNodesAttribs</command>
|
|
|
|
#<table>nodelist</table>
|
|
|
|
#<noderange>blade01-blade02</noderange>
|
|
|
|
#<attr>groups</attr>
|
|
|
|
#<attr>status</attr>
|
|
|
|
#</xcatrequest>
|
|
|
|
#
|
2012-04-23 12:32:58 +00:00
|
|
|
#<xcatresponse>
|
|
|
|
#<node>
|
2012-05-20 18:12:21 +00:00
|
|
|
#<name>nodename</name>
|
2012-04-23 12:32:58 +00:00
|
|
|
#<attr1>value1</attr1>
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#<attrN>valueN</attrN>
|
|
|
|
#</node>
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#</xcatresponse>
|
|
|
|
#
|
|
|
|
#
|
|
|
|
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;
|
2012-05-16 16:25:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-04-23 12:32:58 +00:00
|
|
|
my $rechash = $tab->getNodesAttribs(\@nodes,\@attrs);
|
|
|
|
foreach my $node (@nodes){
|
|
|
|
my $recs = $rechash->{$node};
|
|
|
|
foreach my $rec (@$recs) {
|
2012-08-28 19:37:01 +00:00
|
|
|
my %datseg=();
|
|
|
|
$datseg{name} = [$node];
|
2012-04-23 12:32:58 +00:00
|
|
|
foreach my $key (keys %$rec) {
|
2012-09-13 12:01:48 +00:00
|
|
|
if ($key ne "node") { # do not put in the added node attribute
|
2012-04-23 12:32:58 +00:00
|
|
|
$datseg{$key} = [$rec->{$key}];
|
2012-09-13 12:01:48 +00:00
|
|
|
}
|
2012-04-23 12:32:58 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2012-09-12 13:45:34 +00:00
|
|
|
# getTablesAllNodeAttribs
|
2012-09-13 12:01:48 +00:00
|
|
|
# Read all the nodes from the input tables and get the input attributes
|
2012-09-12 13:45:34 +00:00
|
|
|
# or get ALL attributes, if the word ALL is used.
|
|
|
|
# If the <attr>ALL</attr> is input then read all the attributes
|
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
|
|
|
#<command>getTablesAllNodeAttribs</command>
|
|
|
|
#<table>
|
|
|
|
#<tablename>nodelist</tablename>
|
|
|
|
#<attr>groups</attr>
|
|
|
|
#<attr>status</attr>
|
|
|
|
#</table>
|
|
|
|
#<table>
|
|
|
|
#<tablename>nodetype</tablename>
|
|
|
|
#<attr>ALL</attr>
|
|
|
|
#</table>
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
#</xcatrequest>
|
|
|
|
#
|
|
|
|
#<xcatresponse>
|
|
|
|
#<table>
|
|
|
|
#<tablename>tablename1</tablename>
|
|
|
|
#<node>
|
|
|
|
#<name>n1</name>
|
|
|
|
#<attr1>value1</attr1>
|
|
|
|
#<attr2>value1</attr2>
|
|
|
|
#.
|
|
|
|
#<attrN>valueN</attrN>
|
|
|
|
#</node>
|
|
|
|
#</table>
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
#</xcatresponse>
|
|
|
|
#
|
|
|
|
sub getTablesAllNodeAttribs
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my %rsp;
|
|
|
|
|
|
|
|
# process each table in the request
|
|
|
|
my $tables = $request->{table};
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2012-09-13 12:01:48 +00:00
|
|
|
# read all the nodes and their attributes in this table
|
2012-09-12 13:45:34 +00:00
|
|
|
my @nodeentries = $tab->getAllNodeAttribs(\@attrs);
|
|
|
|
foreach my $node (@nodeentries){
|
|
|
|
# build the node entrys
|
|
|
|
my %datseg=();
|
|
|
|
$datseg{name} = $node->{node};
|
|
|
|
foreach my $at (@attrs) {
|
|
|
|
# if the attribute has a value and is not the node attribute
|
|
|
|
if (($node->{$at}) && ($at ne "node")) {
|
|
|
|
$datseg{$at} = $node->{$at};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2012-04-23 12:32:58 +00:00
|
|
|
|
2012-09-13 18:24:34 +00:00
|
|
|
# getTablesNodesAttribs
|
2012-09-13 12:01:48 +00:00
|
|
|
# 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 <attr>ALL</attr> is input then read all the attributes
|
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
2012-09-13 18:24:34 +00:00
|
|
|
#<command>getTablesNodesAttribs</command>
|
2012-09-13 12:01:48 +00:00
|
|
|
#<noderange>blade01-blade10</noderange>
|
|
|
|
#<table>
|
|
|
|
#<tablename>nodelist</tablename>
|
|
|
|
#<attr>groups</attr>
|
|
|
|
#<attr>status</attr>
|
|
|
|
#</table>
|
|
|
|
#<table>
|
|
|
|
#<tablename>nodetype</tablename>
|
|
|
|
#<attr>ALL</attr>
|
|
|
|
#</table>
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
#</xcatrequest>
|
|
|
|
#
|
|
|
|
#<xcatresponse>
|
|
|
|
#<table>
|
|
|
|
#<tablename>tablename1</tablename>
|
|
|
|
#<node>
|
|
|
|
#<name>n1</name>
|
|
|
|
#<attr1>value1</attr1>
|
|
|
|
#<attr2>value1</attr2>
|
|
|
|
#.
|
|
|
|
#<attrN>valueN</attrN>
|
|
|
|
#</node>
|
|
|
|
#</table>
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
#</xcatresponse>
|
|
|
|
#
|
2012-09-13 18:24:34 +00:00
|
|
|
sub getTablesNodesAttribs
|
2012-09-13 12:01:48 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2012-09-14 13:25:54 +00:00
|
|
|
# getTablesALLRowAttribs
|
|
|
|
# Read all the rows from the input non-Node key'd
|
|
|
|
# tables and get the input attributes
|
|
|
|
# or get ALL attributes, if the word ALL is used.
|
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
|
|
|
#<command>getTablesALLRowAttribs</command>
|
|
|
|
#<table>
|
|
|
|
#<tablename>osimage</tablename>
|
|
|
|
#<attr>imagename</attr>
|
|
|
|
#<attr>synclists</attr>
|
|
|
|
#</table>
|
|
|
|
#<table>
|
|
|
|
#<tablename>linuximage</tablename>
|
|
|
|
#<attr>ALL</attr>
|
|
|
|
#</table>
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
#</xcatrequest>
|
|
|
|
#
|
|
|
|
#<xcatresponse>
|
|
|
|
#<table>
|
|
|
|
#<tablename>osimage</tablename>
|
|
|
|
#<row>
|
|
|
|
#<synclists>value1</synclists>
|
|
|
|
#</row>
|
|
|
|
#<row>
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#</row>
|
|
|
|
#</table>
|
|
|
|
#<table>
|
|
|
|
#<tablename>linuximage</tablename>
|
|
|
|
#<row>
|
|
|
|
#<imagename>value</imagename>
|
|
|
|
#<template>value</template>
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#</row>
|
|
|
|
#<row>
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#</row>
|
|
|
|
#</table>
|
|
|
|
#</xcatresponse>
|
|
|
|
#.
|
|
|
|
#.
|
|
|
|
#
|
|
|
|
sub getTablesAllRowAttribs
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my %rsp;
|
|
|
|
|
|
|
|
# process each table in the request
|
|
|
|
my $tables = $request->{table};
|
|
|
|
foreach my $tabhash (@$tables) {
|
|
|
|
|
|
|
|
my $tablename = $tabhash->{tablename}->[0];
|
|
|
|
my $attr = $tabhash->{attr};
|
|
|
|
my @attrs=@$attr;
|
|
|
|
my $tab=xCAT::Table->new($tablename);
|
|
|
|
my %noderecs;
|
|
|
|
# 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 all the attributes in this table
|
|
|
|
my @recs = $tab->getAllAttribs(@attrs);
|
|
|
|
my %tblrecs;
|
|
|
|
foreach my $rec (@recs) {
|
|
|
|
my %datseg=();
|
|
|
|
foreach my $key (keys %$rec) {
|
|
|
|
$datseg{$key} = $rec->{$key};
|
|
|
|
}
|
|
|
|
push @{$tblrecs{table}->[0]->{row}}, \%datseg;
|
|
|
|
}
|
|
|
|
push @{$rsp{"table"}}, @{$tblrecs{table}};
|
|
|
|
} # end of all table processing
|
|
|
|
# for checkin XML created
|
|
|
|
# my $xmlrec=XMLout(\%rsp,RootName=>'xcatresponse',NoAttr=>1,KeyAttr=>[]);
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return;
|
|
|
|
}
|
2012-04-26 15:19:21 +00:00
|
|
|
#
|
2012-09-12 13:45:34 +00:00
|
|
|
# setNodesAttribs - setNodesAttribs
|
2012-04-26 15:19:21 +00:00
|
|
|
# Sets Nodes attributes for noderange for each of the tables supplied
|
|
|
|
# Example of XML in for this routine
|
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
2012-09-11 11:33:45 +00:00
|
|
|
#<command>setNodesAttribs</command>
|
2012-04-26 15:19:21 +00:00
|
|
|
#<noderange>blade01-blade02</noderange>
|
|
|
|
#<arg>
|
|
|
|
# <table>
|
|
|
|
# <name>nodelist</name>
|
2012-05-16 17:34:18 +00:00
|
|
|
# <attr>
|
2012-05-13 11:44:38 +00:00
|
|
|
# <groups>test</groups>
|
2012-04-26 15:19:21 +00:00
|
|
|
# <comments> This is a another testx</comments>
|
2012-05-16 17:34:18 +00:00
|
|
|
# </attr>
|
2012-04-26 15:19:21 +00:00
|
|
|
# </table>
|
|
|
|
# <table>
|
|
|
|
# <name>nodetype</name>
|
2012-05-16 17:34:18 +00:00
|
|
|
# <attr>
|
2012-04-26 15:19:21 +00:00
|
|
|
# <os>Redhat2</os>
|
|
|
|
# <comments> This is a another testy</comments>
|
2012-05-16 17:34:18 +00:00
|
|
|
# </attr>
|
2012-04-26 15:19:21 +00:00
|
|
|
# </table>
|
|
|
|
#</arg>
|
|
|
|
#</xcatrequest>
|
2012-04-23 12:32:58 +00:00
|
|
|
#
|
2012-09-11 11:33:45 +00:00
|
|
|
sub setNodesAttribs
|
2012-04-23 12:32:58 +00:00
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $cb = shift;
|
2012-05-13 11:44:38 +00:00
|
|
|
my $node = $request->{node}; # added by Client.pm
|
2012-04-26 15:19:21 +00:00
|
|
|
my $noderange = $request->{noderange};
|
2012-04-23 12:32:58 +00:00
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my %rsp;
|
2012-04-26 15:19:21 +00:00
|
|
|
my $args = $request->{arg};
|
|
|
|
my $tables= $args->[0]->{table};
|
|
|
|
# take input an build a request for the nodech function
|
|
|
|
my $newrequest;
|
|
|
|
$newrequest->{noderange} = $request->{noderange};
|
|
|
|
$newrequest->{command}->[0] = "nodech";
|
|
|
|
foreach my $table (@$tables) {
|
|
|
|
my $tablename = $table->{name}->[0];
|
2012-05-13 11:44:38 +00:00
|
|
|
my %keyhash;
|
2012-05-16 17:34:18 +00:00
|
|
|
my $attrs = $table->{attr};
|
2012-04-26 15:19:21 +00:00
|
|
|
foreach my $attrhash (@$attrs) {
|
|
|
|
foreach my $key (keys %$attrhash) {
|
|
|
|
my $tblattr = $tablename;
|
|
|
|
$tblattr .= ".$key=";
|
2012-05-16 17:34:18 +00:00
|
|
|
$tblattr .= $table->{attr}->[0]->{$key}->[0];
|
2012-04-26 15:19:21 +00:00
|
|
|
push (@{$newrequest->{arg}}, $tblattr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-12 13:45:34 +00:00
|
|
|
# nodech will open the table and do all the work
|
2012-04-30 19:36:48 +00:00
|
|
|
if (@$node) {
|
|
|
|
&nodech(\@$node,$newrequest->{arg},$cb,0);
|
|
|
|
} else {
|
|
|
|
my $rsp = {errorcode=>1,error=>"No nodes in noderange"};
|
|
|
|
$cb->(\%rsp);
|
2012-04-26 15:19:21 +00:00
|
|
|
}
|
2012-04-23 12:32:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-05-13 11:44:38 +00:00
|
|
|
#
|
|
|
|
# delEntries
|
|
|
|
# Deletes the table entry based on the input attributes
|
|
|
|
# The attributes and AND'd to together to form the delete request
|
|
|
|
# DELETE FROM nodelist WHERE ("groups" = "compute1,test" AND "status" = "down")
|
|
|
|
# Example of XML in for this routine
|
|
|
|
#
|
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
|
|
|
#<command>delEntries</command>
|
|
|
|
#<table>
|
|
|
|
# <name>nodelist</name>
|
2012-05-16 17:34:18 +00:00
|
|
|
# <attr>
|
2012-05-13 11:44:38 +00:00
|
|
|
# <groups>compute1,test</groups>
|
|
|
|
# <status>down</status>
|
2012-05-16 17:34:18 +00:00
|
|
|
# </attr>
|
2012-05-13 11:44:38 +00:00
|
|
|
#</table>
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
#<table>
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
#</table>
|
|
|
|
#</xcatrequest>
|
|
|
|
#
|
2012-05-16 17:34:18 +00:00
|
|
|
# To delete all entries in a table, you input no attributes
|
2012-05-13 11:44:38 +00:00
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
|
|
|
#<command>delEntries</command>
|
|
|
|
#<table>
|
|
|
|
# <name>nodelist</name>
|
|
|
|
#</table>
|
|
|
|
#</xcatrequest>
|
|
|
|
|
|
|
|
|
|
|
|
sub delEntries
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my %rsp;
|
|
|
|
my $tables= $request->{table};
|
|
|
|
foreach my $table (@$tables) {
|
|
|
|
my $tablename = $table->{name}->[0];
|
|
|
|
my $tab=xCAT::Table->new($tablename);
|
|
|
|
my %keyhash;
|
2012-05-16 17:34:18 +00:00
|
|
|
my $attrs = $table->{attr};
|
2012-05-13 11:44:38 +00:00
|
|
|
foreach my $attrhash (@$attrs) {
|
|
|
|
foreach my $key (keys %$attrhash) {
|
|
|
|
$keyhash{$key} = $attrhash->{$key}->[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (%keyhash) { # delete based on requested attributes
|
|
|
|
$tab->delEntries(\%keyhash); #Yes, delete *all* entries
|
|
|
|
} else { # delete all entries
|
|
|
|
$tab->delEntries(); #delete *all* entries
|
|
|
|
}
|
|
|
|
$tab->commit; # commit
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2012-05-14 19:28:17 +00:00
|
|
|
# getAttribs
|
2012-09-20 15:12:03 +00:00
|
|
|
# Read and returns array of attributes for the key from the input table.
|
|
|
|
# and attributes input. Use "ALL" in the <attr>ALL</attr> for all attributes
|
2012-05-14 19:28:17 +00:00
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
|
|
|
#<command>getAttribs</command>
|
|
|
|
#<table>site</table>
|
|
|
|
#<keys>
|
|
|
|
# <key>domain</key>
|
|
|
|
#</keys>
|
2012-05-16 17:34:18 +00:00
|
|
|
#<attr>value</attr>
|
|
|
|
#<attr>comments</attr>
|
2012-05-14 19:28:17 +00:00
|
|
|
#</xcatrequest>
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#<xcatresponse>
|
|
|
|
#<value>{domain value}</value>
|
|
|
|
#<comments>This is a comment</comments>
|
|
|
|
#</xcatresponse>
|
|
|
|
sub getAttribs
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my $tablename = $request->{table}->[0];
|
2012-05-16 17:34:18 +00:00
|
|
|
my $attr = $request->{attr};
|
2012-05-14 19:28:17 +00:00
|
|
|
my @attrs= @$attr;
|
|
|
|
my $tab=xCAT::Table->new($tablename);
|
|
|
|
my %rsp;
|
|
|
|
my %keyhash;
|
2012-09-20 15:12:03 +00:00
|
|
|
# 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;
|
|
|
|
}
|
|
|
|
}
|
2012-05-14 19:28:17 +00:00
|
|
|
foreach my $k (keys %{$request->{keys}->[0]}) {
|
|
|
|
$keyhash{$k} = $request->{keys}->[0]->{$k}->[0];
|
|
|
|
}
|
|
|
|
my $recs = $tab->getAttribs(\%keyhash,\@attrs);
|
|
|
|
|
|
|
|
if ($recs) {
|
|
|
|
my %attrhash=%$recs;
|
|
|
|
foreach my $k (keys %attrhash) {
|
|
|
|
|
|
|
|
push @{$rsp{$k}}, $recs->{$k};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return;
|
|
|
|
}
|
2012-05-16 17:34:18 +00:00
|
|
|
# setAttribs
|
|
|
|
# Set the attributes for the key(s) input in the table.
|
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
|
|
|
#<command>setAttribs</command>
|
|
|
|
#<table>site</table>
|
|
|
|
#<keys>
|
|
|
|
# <key>domain</key>
|
|
|
|
#</keys>
|
|
|
|
#<attr>
|
|
|
|
# <value>cluster.net</value>
|
|
|
|
# <comments>This is a comment</comments>
|
|
|
|
#</xcatrequest>
|
|
|
|
#
|
|
|
|
sub setAttribs
|
|
|
|
{
|
|
|
|
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 %keyhash;
|
|
|
|
my %attrhash;
|
|
|
|
foreach my $k (keys %{$request->{keys}->[0]}) {
|
|
|
|
$keyhash{$k} = $request->{keys}->[0]->{$k}->[0];
|
|
|
|
}
|
|
|
|
foreach my $a (keys %{$request->{attr}->[0]}) {
|
|
|
|
$attrhash{$a} = $request->{attr}->[0]->{$a}->[0];
|
|
|
|
}
|
|
|
|
$tab->setAttribs(\%keyhash,\%attrhash);
|
|
|
|
return;
|
|
|
|
}
|
2012-05-20 18:12:21 +00:00
|
|
|
# noderange
|
|
|
|
# Expands the input noderange into a list of nodes.
|
|
|
|
#<xcatrequest>
|
|
|
|
#<clienttype>PCM</clienttype>
|
|
|
|
#<command>noderange</command>
|
|
|
|
#<noderange>compute1-compute2</noderange>
|
|
|
|
#</xcatrequest>
|
|
|
|
#<xcatresponse>
|
|
|
|
#<node>nodename1</node>
|
|
|
|
# .
|
|
|
|
# .
|
|
|
|
#<node>nodenamern1</node>
|
|
|
|
#</xcatresponse>
|
|
|
|
sub NodeRange
|
|
|
|
{
|
|
|
|
my $request = shift;
|
|
|
|
my $cb = shift;
|
|
|
|
my $command = $request->{command}->[0];
|
|
|
|
my %rsp;
|
|
|
|
my $node=$request->{node};
|
|
|
|
my @nodes = @$node;
|
|
|
|
foreach my $node (@nodes){
|
|
|
|
push @{$rsp{"node"}}, $node;
|
|
|
|
|
|
|
|
}
|
|
|
|
$cb->(\%rsp);
|
|
|
|
return;
|
|
|
|
}
|