From 4068ba6e818e43d3d35e4554b897988c00b72fd8 Mon Sep 17 00:00:00 2001 From: vallard Date: Wed, 3 Feb 2010 22:06:43 +0000 Subject: [PATCH] added support for tabch git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5130 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/tabutils.pm | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/xCAT-server/lib/xcat/plugins/tabutils.pm b/xCAT-server/lib/xcat/plugins/tabutils.pm index 81e35a2bd..2136a0f9f 100644 --- a/xCAT-server/lib/xcat/plugins/tabutils.pm +++ b/xCAT-server/lib/xcat/plugins/tabutils.pm @@ -134,6 +134,9 @@ sub process_request { return tabgrep($nodes, $callback); } + elsif ($command eq "tabch"){ + return tabgrep($args, $callback); + } else { print "$command not implemented yet\n"; @@ -1376,3 +1379,54 @@ sub nodels return 0; } + +######### +# tabch +######### +sub tabch { + my $args = shift; + my $callback = shift; + my @ARGV = @{$args}; + my $target = shift @ARGV; + my %tables; + my %keyhash=(); + my @keypairs=split(/,/,$target); + if ($keypairs[0] !~ /([^\.\=]+)\.([^\.\=]+)\=(.+)/) { + foreach (@keypairs) { + m/(.*)=(.*)/; + my $key=$1; + my $val=$2; + $keyhash{$key}=$val; + } + } 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); + } + } + $tableupdates{$table}{$column}=$value; + } + + #commit all the changes + foreach (keys %tables) { + if (exists($tableupdates{$_})) { + $tables{$_}->setAttribs(\%keyhash,\%{$tableupdates{$_}}); + } + $tables{$_}->commit; + } +} +