added tabch -d so that you can also delete records.

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5131 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
vallard 2010-02-04 04:03:46 +00:00
parent 4068ba6e81
commit 4a8403596c

View File

@ -135,7 +135,7 @@ sub process_request
return tabgrep($nodes, $callback);
}
elsif ($command eq "tabch"){
return tabgrep($args, $callback);
return tabch($args, $callback);
}
else
{
@ -1387,6 +1387,13 @@ sub tabch {
my $args = shift;
my $callback = shift;
my @ARGV = @{$args};
my $delete = 0;
my $fo = $ARGV[0];
if($ARGV[0] =~ /^-d$/){
shift @ARGV;
$delete = 1;
}
my $target = shift @ARGV;
my %tables;
my %keyhash=();
@ -1401,32 +1408,46 @@ sub tabch {
} else {
unshift(@ARGV, $target);
}
my %tableupdates;
for (@ARGV) {
my $temp;
my $table;
my $column;
my $value;
($table,$temp) = split('\.',$_,2);
($column,$value) = split("=",$temp,2);
unless ($tables{$table}) {
my $tab = xCAT::Table->new($table,-create => 1,-autocommit => 0);
if ($tab) {
$tables{$table}=$tab;
} else {
print "Table $table does not exist.\n";
exit(1);
}
if($delete){
my @tables_to_del=@ARGV;
if(@tables_to_del == 0){
$callback->({error => ["Missing table name."],errorcode=>[1]});
return;
}
for(@tables_to_del){
$tables{$_} = xCAT::Table->new($_,-create=> 1,-autocommit => 0);
$tables{$_}->delEntries(\%keyhash);
$tables{$_}->commit;
}
}else{
my %tableupdates;
for (@ARGV) {
my $temp;
my $table;
my $column;
my $value;
($table,$temp) = split('\.',$_,2);
($column,$value) = split("=",$temp,2);
unless ($tables{$table}) {
my $tab = xCAT::Table->new($table,-create => 1,-autocommit => 0);
if ($tab) {
$tables{$table}=$tab;
} else {
$callback->({error => [ "Table $table does not exist."],errorcode=>[1]});
}
}
$tableupdates{$table}{$column}=$value;
}
#commit all the changes
foreach (keys %tables) {
if (exists($tableupdates{$_})) {
$tables{$_}->setAttribs(\%keyhash,\%{$tableupdates{$_}});
}
$tables{$_}->commit;
}
$tableupdates{$table}{$column}=$value;
}
#commit all the changes
foreach (keys %tables) {
if (exists($tableupdates{$_})) {
$tables{$_}->setAttribs(\%keyhash,\%{$tableupdates{$_}});
}
$tables{$_}->commit;
}
}