From aceb17bc7fb2d022ea6030eeef1125e694efb445 Mon Sep 17 00:00:00 2001 From: bp-sawyers <bp-sawyers@8638fb3e-16cb-4fca-ae20-7b5d299a9bcd> Date: Mon, 18 Feb 2008 15:57:25 +0000 Subject: [PATCH] Fixed errors in the client/server communication for xdsh and db-cmds and MsgUtils git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@505 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT-2.0/xCAT/Client.pm | 22 +- perl-xCAT-2.0/xCAT/DSHCLI.pm | 466 ++++++++++---------- perl-xCAT-2.0/xCAT/MsgUtils.pm | 119 +++-- xCAT-client-2.0/bin/xcatDBcmds | 157 +------ xCAT-client-2.0/bin/xdsh | 177 +------- xCAT-client-2.0/pods/man1/tabdump.1.pod | 13 +- xCAT-client-2.0/pods/man1/tabrestore.1.pod | 15 +- xCAT-client-2.0/share/man/man1/tabdump.1 | 19 +- xCAT-client-2.0/share/man/man1/tabrestore.1 | 21 +- xCAT-server-2.0/lib/xcat/plugins/xdsh.pm | 53 +-- 10 files changed, 395 insertions(+), 667 deletions(-) diff --git a/perl-xCAT-2.0/xCAT/Client.pm b/perl-xCAT-2.0/xCAT/Client.pm index d803027c8..7d7defc68 100644 --- a/perl-xCAT-2.0/xCAT/Client.pm +++ b/perl-xCAT-2.0/xCAT/Client.pm @@ -484,22 +484,31 @@ sub build_response { ########################################## sub handle_response { my $rsp = shift; +#print "in handle_response\n"; # Handle errors if ($rsp->{errorcode}) { if (ref($rsp->{errorcode}) eq 'ARRAY') { foreach my $ecode (@{$rsp->{errorcode}}) { $xCAT::Client::EXITCODE |= $ecode; } } else { $xCAT::Client::EXITCODE |= $rsp->{errorcode}; } # assume it is a non-reference scalar } + if ($rsp->{error}) { +#print "printing error\n"; + if (ref($rsp->{error}) eq 'ARRAY') { foreach my $text (@{$rsp->{error}}) { print "Error: $text\n"; } } + else { print ("Error: ".$rsp->{error}."\n"); } + } if ($rsp->{warning}) { - if (ref($rsp->{warning}) eq 'ARRAY') { print ("Warning: " . $rsp->{warning}->[0] . "\n"); } +#print "printing warning\n"; + if (ref($rsp->{warning}) eq 'ARRAY') { foreach my $text (@{$rsp->{warning}}) { print "Warning: $text\n"; } } else { print ("Warning: ".$rsp->{warning}."\n"); } } - if ($rsp->{error}) { - if (ref($rsp->{error}) eq 'ARRAY') { print ("Error: " . $rsp->{error}->[0] . "\n"); } - else { print ("Error: ".$rsp->{error}."\n"); } + if ($rsp->{info}) { +#print "printing info\n"; + if (ref($rsp->{info}) eq 'ARRAY') { foreach my $text (@{$rsp->{info}}) { print "$text\n"; } } + else { print ($rsp->{info}."\n"); } } # Handle {node} structure - if ($rsp->{node}) { + if (scalar @{$rsp->{node}}) { +#print "printing node\n"; my $nodes=($rsp->{node}); my $node; foreach $node (@$nodes) { @@ -527,7 +536,8 @@ sub handle_response { } # Handle {data} structure with no nodes - if ($rsp->{data}) { + if (scalar @{$rsp->{data}}) { +#print "printing data\n"; my $data=($rsp->{data}); my $data_entry; foreach $data_entry (@$data) { diff --git a/perl-xCAT-2.0/xCAT/DSHCLI.pm b/perl-xCAT-2.0/xCAT/DSHCLI.pm index d26354f0d..fc0f2411f 100644 --- a/perl-xCAT-2.0/xCAT/DSHCLI.pm +++ b/perl-xCAT-2.0/xCAT/DSHCLI.pm @@ -62,13 +62,13 @@ $| = 1; Returns: The number of targets that failed to execute a remote copy command - + Globals: None - + Error: None - + Example: Comments: @@ -94,8 +94,8 @@ sub execute_dcp if (!scalar(%resolved_targets)) { my %rsp; - $rsp->{data}->[0] = "No hosts in node list\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + $rsp->{data}->[0] = "No hosts in node list"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); return ++$result; } @@ -111,8 +111,8 @@ sub execute_dcp # ) #{ # my %rsp; - # $rsp->{data}->[0] = " The DSH fanout value has exceeded the system file descriptor upper limit. Please either reduce the fanout value, or increase max file descriptor number by running ulimit.\n"; - # xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + # $rsp->{data}->[0] = " The DSH fanout value has exceeded the system file descriptor upper limit. Please either reduce the fanout value, or increase max file descriptor number by running ulimit."; + # xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); # return ++$result; #} @@ -153,9 +153,9 @@ sub execute_dcp my @active_list = keys(%targets_active); my %rsp; $rsp->{data}->[0] = - " Timed out waiting for response from child processes for the following nodes.\n"; - $rsp->{data}->[1] = " @active_list\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + " Timed out waiting for response from child processes for the following nodes."; + $rsp->{data}->[1] = " @active_list"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); kill 'INT', keys(%pid_targets); $result++; last; @@ -259,13 +259,13 @@ sub execute_dcp Returns: The number of targets that failed to execute a remote shell command - + Globals: None - + Error: None - + Example: Comments: @@ -319,8 +319,8 @@ sub execute_dsh if (!scalar(%resolved_targets)) { my %rsp; - $rsp->{data}->[0] = " No hosts in node list\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + $rsp->{data}->[0] = " No hosts in node list"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); return ++$result; } $dsh_exec_state++; @@ -342,8 +342,8 @@ sub execute_dsh #) #{ # my %rsp; - # $rsp->{data}->[0] = " The DSH fanout value has exceeded the system file descriptor upper limit. Please either reduce the fanout value, or increase max file descriptor number by running ulimit.\n"; - # xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + # $rsp->{data}->[0] = " The DSH fanout value has exceeded the system file descriptor upper limit. Please either reduce the fanout value, or increase max file descriptor number by running ulimit."; + # xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); # return ++$result; #} @@ -378,13 +378,13 @@ sub execute_dsh Returns: @targets_failed - a list of those targets that failed execution - + Globals: None - + Error: None - + Example: Comments: @@ -447,9 +447,9 @@ sub _execute_dsh my @active_list = keys(%targets_active); my %rsp; $rsp->{data}->[0] = - " Timed out waiting for response from child processes for the followint nodes. Terminating the child processes. \n"; - $rsp->{data}->[1] = " @active_list\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + " Timed out waiting for response from child processes for the followint nodes. Terminating the child processes. "; + $rsp->{data}->[1] = " @active_list"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); @targets_failed = keys(%targets_active); &handle_signal_dsh('INT', 1); @@ -554,8 +554,8 @@ sub _execute_dsh my %rsp; $rsp->{data}->[0] = - " $user_target remote Command return code = $exit_code.\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + " $user_target remote Command return code = $exit_code."; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); my %rsp; $rsp->{data}->[0] = "dsh> Remote_command_failed $user_target"; @@ -575,14 +575,14 @@ sub _execute_dsh my %rsp; $rsp->{data}->[0] = - " $user_target remote Command return code = $$target_properties{'target-rc'}.\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + " $user_target remote Command return code = $$target_properties{'target-rc'}."; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); my %rsp; $rsp->{data}->[0] = "dsh> Remote_command_failed $user_target"; $$options{'monitor'} - && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); + && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK, 1); push @targets_failed, $user_target; push @{$dsh_target_status{'failed'}}, $user_target @@ -594,8 +594,8 @@ sub _execute_dsh my %rsp; $rsp->{data}->[0] = - " A return code for the command run on the host $isre_target was not received.\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + " A return code for the command run on the host $isre_target was not received."; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); my %rsp; $rsp->{data}->[0] = "dsh> Remote_command_failed $user_target"; @@ -673,14 +673,14 @@ sub _execute_dsh $options - options hash table describing dshservice configuration options Returns: - None - + None + Globals: None - + Error: None - + Example: Comments: @@ -708,7 +708,7 @@ sub execute_dshservice if (!(-e "$::CONTEXT_DIR$$options{'context'}.pm")) { my %rsp; - $rsp->{data}->[0] = " Context: $$options{'context'} not valid.\n"; + $rsp->{data}->[0] = " Context: $$options{'context'} not valid."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return ++$result; @@ -775,7 +775,7 @@ sub execute_dshservice { my %rsp; - $rsp->{data}->[0] = " Context: $$options{'context'} not valid.\n"; + $rsp->{data}->[0] = " Context: $$options{'context'} not valid."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return ++$result; } @@ -819,16 +819,16 @@ sub execute_dshservice $errfh_targets - hash table of STDERR pipe handles keyed by target name $targets_waiting - array of targets pending remote execution $targets_active - hash table of currently active targets with output possibly available - + Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -953,7 +953,7 @@ sub fork_fanout_dcp } my %rsp; - $rsp->{data}->[0] = " TRACE: Executing Command:@dcp_command\n"; + $rsp->{data}->[0] = " TRACE: Executing Command:@dcp_command"; $dsh_trace && (xCAT::MsgUtils->message("I", $rsp, $::CALLBACK)); @@ -990,16 +990,16 @@ sub fork_fanout_dcp $errfh_targets - hash table of STDERR pipe handles keyed by target name $targets_waiting - array of targets pending remote execution $targets_active - hash table of currently active targets with output possibly available - + Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -1093,7 +1093,7 @@ sub fork_fanout_dsh { my %rsp; - $rsp->{data}->[0] = "TRACE: Environment option specified\n"; + $rsp->{data}->[0] = "TRACE: Environment option specified"; $dsh_trace && (xCAT::MsgUtils->message("I", $rsp, $::CALLBACK)); my %env_rcp_config = (); $tmp_env_file = POSIX::tmpnam . '.dsh'; @@ -1127,7 +1127,7 @@ sub fork_fanout_dsh my %rsp; $rsp->{data}->[0] = - "TRACE:Environment: Exporting File.@env_rcp_command \n"; + "TRACE:Environment: Exporting File.@env_rcp_command "; $dsh_trace && (xCAT::MsgUtils->message("I", $rsp, $::CALLBACK)); my @env_rcp_process = @@ -1139,7 +1139,7 @@ sub fork_fanout_dsh { my %rsp; - $rsp->{data}->[0] = "TRACE: Execute option specified.\n"; + $rsp->{data}->[0] = "TRACE: Execute option specified."; $dsh_trace && (xCAT::MsgUtils->message("I", $rsp, $::CALLBACK)); my %exe_rcp_config = (); @@ -1177,7 +1177,7 @@ sub fork_fanout_dsh my %rsp; $rsp->{data}->[0] = - "TRACE:Execute: Exporting File:@exe_rcp_command\n"; + "TRACE:Execute: Exporting File:@exe_rcp_command"; $dsh_trace && (xCAT::MsgUtils->message("I", $rsp, $::CALLBACK)); my @exe_rcp_process = xCAT::DSHCore->fork_no_output($user_target, @exe_rcp_command); @@ -1209,7 +1209,7 @@ sub fork_fanout_dsh my @process_info; my %rsp; - $rsp->{data}->[0] = "Command name: @dsh_command\n"; + $rsp->{data}->[0] = "Command name: @dsh_command"; $dsh_trace && (xCAT::MsgUtils->message("I", $rsp, $::CALLBACK)); my %rsp; @@ -1221,7 +1221,7 @@ sub fork_fanout_dsh { my %rsp; $rsp->{data}->[0] = - "$user_target could not execute this command $dsh_command[0] - $$options{'command'} , $! \n"; + "$user_target could not execute this command $dsh_command[0] - $$options{'command'} , $! "; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); } @@ -1231,7 +1231,7 @@ sub fork_fanout_dsh { my %rsp; - $rsp->{data}->[0] = "Cannot redirect STDOUT, error= $!\n"; + $rsp->{data}->[0] = "Cannot redirect STDOUT, error= $!"; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); } @@ -1239,7 +1239,7 @@ sub fork_fanout_dsh { my %rsp; - $rsp->{data}->[0] = "Cannot redirect STDERR, error= $!\n"; + $rsp->{data}->[0] = "Cannot redirect STDERR, error= $!"; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); } @@ -1278,16 +1278,16 @@ sub fork_fanout_dsh $output_files - list of output file handles where output is to be written $error_files - list of error file handles where error output is to be written $select_err_fhs - list of currently available STDERR pipe handles - + Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -1347,7 +1347,7 @@ sub buffer_output if ($pid == -1) { # no child waiting ignore my %rsp; - $rsp->{data}->[0] = "waitpid call PID=$pid. Ignore.\n"; + $rsp->{data}->[0] = "waitpid call PID=$pid. Ignore."; $$options{'monitor'} && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); } @@ -1410,13 +1410,13 @@ sub buffer_output Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -1475,7 +1475,7 @@ sub buffer_error if ($pid == -1) { # no child waiting my %rsp; - $rsp->{data}->[0] = "waitpid call PID=$pid. Ignore.\n"; + $rsp->{data}->[0] = "waitpid call PID=$pid. Ignore."; $$options{'monitor'} && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); } @@ -1537,13 +1537,13 @@ sub buffer_error Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -1597,7 +1597,7 @@ sub stream_output if ($pid == -1) { # no child waiting my %rsp; - $rsp->{data}->[0] = "waitpid call PID=$pid. Ignore.\n"; + $rsp->{data}->[0] = "waitpid call PID=$pid. Ignore."; $$options{'monitor'} && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); } @@ -1612,7 +1612,7 @@ sub stream_output { my %rsp; $rsp->{data}->[0] = - "$user_target remote shell had error code: $exit_code\n"; + "$user_target remote shell had error code: $exit_code"; !$$options{'silent'} && (xCAT::MsgUtils->message("E", $rsp, $::CALLBACK)); @@ -1635,7 +1635,7 @@ sub stream_output my %rsp; $rsp->{data}->[0] = - " $user_target remote Command had return code: $$target_properties{'target-rc'} \n"; + " $user_target remote Command had return code: $$target_properties{'target-rc'} "; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); my %rsp; @@ -1652,7 +1652,7 @@ sub stream_output my %rsp; $rsp->{data}->[0] = - " $user_target a return code run on this host was not received. \n"; + " $user_target a return code run on this host was not received. "; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); my %rsp; @@ -1711,13 +1711,13 @@ sub stream_output Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -1771,7 +1771,7 @@ sub stream_error if ($pid == -1) { # no child waiting my %rsp; - $rsp->{data}->[0] = "waitpid call PID=$pid. Ignore.\n"; + $rsp->{data}->[0] = "waitpid call PID=$pid. Ignore."; $$options{'monitor'} && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); } @@ -1786,7 +1786,7 @@ sub stream_error { my %rsp; $rsp->{data}->[0] = - " $user_target remote shell had exit code $exit_code.\n"; + " $user_target remote shell had exit code $exit_code."; !$$options{'silent'} && (xCAT::MsgUtils->message("E", $rsp, $::CALLBACK)); @@ -1809,7 +1809,7 @@ sub stream_error my %rsp; rsp->{data}->[0] = - "$user_target remote command had return code $$target_properties{'target-rc'}\n"; + "$user_target remote command had return code $$target_properties{'target-rc'}"; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); my %rsp; @@ -1826,7 +1826,7 @@ sub stream_error my %rsp; $rsp->{data}->[0] = - "A return code for the command run on $user_target was not received.\n"; + "A return code for the command run on $user_target was not received."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); my %rsp; @@ -1872,13 +1872,13 @@ sub stream_error Returns: The name of the default context - + Globals: None - + Error: None - + Example: Comments: @@ -1914,19 +1914,19 @@ sub config_default_context This routine configures the command environment for an instance of the dcp command based on the configuration of the DSH Utilities environment defined in $options. - + Arguments: $options - options hash table describing dsh configuration options Returns: Number of configuration errors - + Globals: None - + Error: None - + Example: Comments: @@ -1950,13 +1950,13 @@ sub config_dcp { my %rsp; - $rsp->{data}->[0] = "Invalid context specified:$$options{'context'}.\n"; + $rsp->{data}->[0] = "Invalid context specified:$$options{'context'}."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return ++$result; } my %rsp; - $rsp->{data}->[0] = "TRACE:Default context is $$options{'context'}.\n"; + $rsp->{data}->[0] = "TRACE:Default context is $$options{'context'}."; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); @@ -1998,14 +1998,14 @@ sub config_dcp $$options{'fanout'} = $$options{'fanout'} || $ENV{'DSH_FANOUT'} || 64; my %rsp; - $rsp->{data}->[0] = "TRACE:Fanout Value is $$options{'fanout'}.\n"; + $rsp->{data}->[0] = "TRACE:Fanout Value is $$options{'fanout'}."; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); $$options{'timeout'} = $$options{'timeout'} || $ENV{'DSH_TIMEOUT'} || undef; my %rsp; - $rsp->{data}->[0] = "TRACE:Timeout Value is $$options{'timeout'}.\n"; + $rsp->{data}->[0] = "TRACE:Timeout Value is $$options{'timeout'}."; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); @@ -2068,7 +2068,7 @@ sub config_dcp { my %rsp; $rsp->{data}->[0] = - "Cannot copy to target $$options{'target'}. Directory does not exist.\n"; + "Cannot copy to target $$options{'target'}. Directory does not exist."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return ++$result; } @@ -2090,13 +2090,13 @@ sub config_dcp Returns: Number of configuration errors - + Globals: None - + Error: None - + Example: Comments: @@ -2147,13 +2147,13 @@ sub config_dsh { my %rsp; - $rsp->{data}->[0] = "Invalid context specified: $$options{'context'}\n"; + $rsp->{data}->[0] = "Invalid context specified: $$options{'context'}"; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return ++$result; } my %rsp; - $rsp->{data}->[0] = "TRACE:Default context is $$options{'context'}\n"; + $rsp->{data}->[0] = "TRACE:Default context is $$options{'context'}"; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); @@ -2163,7 +2163,7 @@ sub config_dsh || undef); my %rsp; - $rsp->{data}->[0] = "TRACE:Node RSH is $$options{'node-rsh'}\n"; + $rsp->{data}->[0] = "TRACE:Node RSH is $$options{'node-rsh'}"; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); @@ -2214,7 +2214,7 @@ sub config_dsh if ($$options{'environment'} && (-z $$options{'environment'})) { my %rsp; - $rsp->{data}->[0] = "File: $$options{'environment'} is empty.\n"; + $rsp->{data}->[0] = "File: $$options{'environment'} is empty."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); $$options{'environment'} = undef; } @@ -2222,7 +2222,7 @@ sub config_dsh $$options{'fanout'} = $$options{'fanout'} || $ENV{'DSH_FANOUT'} || 64; my %rsp; - $rsp->{data}->[0] = "TRACE: Fanout value is $$options{'fanout'}.\n"; + $rsp->{data}->[0] = "TRACE: Fanout value is $$options{'fanout'}."; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); @@ -2236,7 +2236,7 @@ sub config_dsh { my %rsp; $rsp->{data}->[0] = - "Incorrect argument \"$$options{'syntax'}\" specified on -S flag. \n"; + "Incorrect argument \"$$options{'syntax'}\" specified on -S flag. "; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return ++$result; } @@ -2257,7 +2257,7 @@ sub config_dsh $$options{'timeout'} = $$options{'timeout'} || $ENV{'DSH_TIMEOUT'} || undef; my %rsp; - $rsp->{data}->[0] = "TRACE: Timeout value is $$options{'timeout'} \n"; + $rsp->{data}->[0] = "TRACE: Timeout value is $$options{'timeout'} "; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); @@ -2386,7 +2386,7 @@ sub config_dsh { my %rsp; - $rsp->{data}->[0] = "File $exe_command[0] does not exist\n"; + $rsp->{data}->[0] = "File $exe_command[0] does not exist"; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return ++$result; } @@ -2395,7 +2395,7 @@ sub config_dsh { my %rsp; - $rsp->{data}->[0] = "File $exe_command[0] is empty.\n"; + $rsp->{data}->[0] = "File $exe_command[0] is empty."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return ++$result; } @@ -2404,7 +2404,7 @@ sub config_dsh { my %rsp; - $rsp->{data}->[0] = "File $exe_command[0] is not executable.\n"; + $rsp->{data}->[0] = "File $exe_command[0] is not executable."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); return ++$result; } @@ -2427,13 +2427,13 @@ sub config_dsh Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -2495,13 +2495,13 @@ sub config_signals_dsh Returns: None - + Globals: $dsh_execution_state - current state of dsh execution - + Error: None - + Example: Comments: @@ -2524,7 +2524,7 @@ sub handle_signal_dsh { my %rsp; $rsp->{data}->[0] = - "Command execution ended prematurely due to a previous error or stop request from the user.\n"; + "Command execution ended prematurely due to a previous error or stop request from the user."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); exit(1); } @@ -2533,7 +2533,7 @@ sub handle_signal_dsh { my %rsp; $rsp->{data}->[0] = - "Command execution ended prematurely due to a previous error or stop request from the user.\n"; + "Command execution ended prematurely due to a previous error or stop request from the user."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); exit(1); @@ -2556,7 +2556,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "Running the command on $user_target has been cancelled due to unrecoverable error. The command was never sent to the host.\n"; + "Running the command on $user_target has been cancelled due to unrecoverable error. The command was never sent to the host."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); } @@ -2576,7 +2576,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "Running the command on $user_target has been cancelled due to unrecoverable error or stop request by user.\nNo commands were executed on any host.\n"; + "Running the command on $user_target has been cancelled due to unrecoverable error or stop request by user.\nNo commands were executed on any host."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); if ($$dsh_options{'stats'}) @@ -2614,7 +2614,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "$user_target: running of the command on this host has been cancelled due to unrecoverable error.\n The command was never sent to the host.\n"; + "$user_target: running of the command on this host has been cancelled due to unrecoverable error.\n The command was never sent to the host."; xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); } @@ -2623,7 +2623,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "$user_target: running of the command on this host has been cancelled due to unrecoverable error or stop request by user.\n The command was never sent to the host.\n"; + "$user_target: running of the command on this host has been cancelled due to unrecoverable error or stop request by user.\n The command was never sent to the host."; xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); my %rsp; @@ -2641,7 +2641,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "Command execution ended prematurely due to a previous unrecoverable error or stop by user.\n No commands were executed on any host.\n"; + "Command execution ended prematurely due to a previous unrecoverable error or stop by user.\n No commands were executed on any host."; if ($$dsh_options{'stats'}) { @@ -2674,7 +2674,7 @@ sub handle_signal_dsh { my %rsp; $rsp->{data}->[0] = - "Caught SIG$signal - terminating the child processes.\n"; + "Caught SIG$signal - terminating the child processes."; !$$dsh_options{'stats'} && xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); @@ -2698,7 +2698,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "Running the command on $user_target has been interrupted due to unrecoverable error. The command may not have completed successfully.\n"; + "Running the command on $user_target has been interrupted due to unrecoverable error. The command may not have completed successfully."; xCAT::MsgUtils->message("V", $rsp, $::CALLBACK); } @@ -2707,7 +2707,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "Running the command on $user_target has been interrupted due to unrecoverable error or stop request by the user. The command may not have completed successfully.\n"; + "Running the command on $user_target has been interrupted due to unrecoverable error or stop request by the user. The command may not have completed successfully."; xCAT::MsgUtils->message("V", $rsp, $::CALLBACK); } } @@ -2730,7 +2730,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "Running the command on $user_target has been cancelled due to unrecoverable error. The command was never sent to the host.\n"; + "Running the command on $user_target has been cancelled due to unrecoverable error. The command was never sent to the host."; xCAT::MsgUtils->message("V", $rsp, $::CALLBACK); } @@ -2739,7 +2739,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "Running the command on $user_target has been cancelled due to unrecoverable error or stop request by the user. The command was never sent to the host.\n"; + "Running the command on $user_target has been cancelled due to unrecoverable error or stop request by the user. The command was never sent to the host."; xCAT::MsgUtils->message("V", $rsp, $::CALLBACK); my %rsp; @@ -2757,7 +2757,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "Command execution ended prematurely due to a previous unrecoverable error or stop request by the user.\n"; + "Command execution ended prematurely due to a previous unrecoverable error or stop request by the user."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); if ($$dsh_options{'stats'}) @@ -2782,7 +2782,7 @@ sub handle_signal_dsh my %rsp; $rsp->{data}->[0] = - "Running the command stopped due to unrecoverable error or stop request by the user.\n"; + "Running the command stopped due to unrecoverable error or stop request by the user."; xCAT::MsgUtils->message("V", $rsp, $::CALLBACK); return; @@ -2792,7 +2792,7 @@ sub handle_signal_dsh { my %rsp; $rsp->{data}->[0] = - "Running the command stopped due to unrecoverable error or stop request by the user.\n"; + "Running the command stopped due to unrecoverable error or stop request by the user."; xCAT::MsgUtils->message("V", $rsp, $::CALLBACK); exit(1); } @@ -2816,13 +2816,13 @@ sub handle_signal_dsh Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -2857,13 +2857,13 @@ sub resolve_targets Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -2901,7 +2901,7 @@ sub resolve_nodes _resolve_nodes Wrapper routine for resolve_all_nodes, resolve_nodes and - + Arguments: $options - options hash table describing dsh configuration options @@ -2912,13 +2912,13 @@ sub resolve_nodes Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -2952,7 +2952,7 @@ sub _resolve_nodes my %rsp; $rsp->{data}->[0] = - "The specified node $node is not defined to the cluster.\n"; + "The specified node $node is not defined to the cluster."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); } @@ -2985,13 +2985,13 @@ sub _resolve_nodes Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -3012,7 +3012,7 @@ sub verify_targets { my $target = $context->verify_target(); my %rsp; - $rsp->{data}->[0] = "TRACE:Verifying $hostname with $target.\n"; + $rsp->{data}->[0] = "TRACE:Verifying $hostname with $target."; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); } @@ -3022,7 +3022,7 @@ sub verify_targets { my $target = $context->verify_target(); my %rsp; - $rsp->{data}->[0] = "TRACE:Verifying $hostname with $target.\n"; + $rsp->{data}->[0] = "TRACE:Verifying $hostname with $target."; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); @@ -3031,7 +3031,7 @@ sub verify_targets { my %rsp; $rsp->{data}->[0] = - "$user_target is not responding. No command will be issued to this host.\n"; + "$user_target is not responding. No command will be issued to this host."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); my %rsp; @@ -3060,7 +3060,7 @@ sub verify_targets my @no_response = (); my %rsp; $rsp->{data}->[0] = - "TRACE:Verifying remaining targets with pping command.\n"; + "TRACE:Verifying remaining targets with pping command."; $dsh_trace && xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); @no_response = xCAT::DSHCore->pping_hostnames(@ping_list); @@ -3072,7 +3072,7 @@ sub verify_targets { my %rsp; $rsp->{data}->[0] = - "$user_target is not responding. No command will be issued to this host.\n"; + "$user_target is not responding. No command will be issued to this host."; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); my %rsp; @@ -3102,13 +3102,13 @@ sub verify_targets Returns: A list of available contexts in the DSH environment - + Globals: None - + Error: None - + Example: Comments: @@ -3145,13 +3145,13 @@ sub get_available_contexts Returns: A hash table of configuration properties grouped by context - + Globals: None - + Error: None - + Example: Comments: @@ -3184,13 +3184,13 @@ sub get_dsh_config Returns: A hash table of default properties for each context - + Globals: None - + Error: None - + Example: Comments: @@ -3225,13 +3225,13 @@ sub get_dsh_defaults Returns: A list of valid contexts - + Globals: None - + Error: None - + Example: Comments: @@ -3265,13 +3265,13 @@ sub get_valid_contexts Returns: None - + Globals: None - + Error: None - + Example: Comments: @@ -3376,7 +3376,7 @@ sub check_valid_options #------------------------------------------------------------------------------- -=head3 +=head3 ignoreEnv @@ -3415,7 +3415,7 @@ sub ignoreEnv { $env = join ",", @env_not_valid; my %rsp; - $rsp->{data}->[0] = "Invalid Environment Variable: $env\n"; + $rsp->{data}->[0] = "Invalid Environment Variable: $env"; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); exit 1; } @@ -3430,7 +3430,7 @@ sub ignoreEnv #-------------------------------------------------------------------------------- -=head3 +=head3 isFdNumExceed check if file descriptor number exceed the max number in ulimit @@ -3449,7 +3449,7 @@ sub ignoreEnv None Example: xCAT::DSHCLI->check_fd_num(2, scalar( keys(%resolved_targets)), $$options{'fanout'}) - + Comments: none @@ -3482,7 +3482,7 @@ sub isFdNumExceed if ($fdnum !~ /\s*\d+\s*/) #this should never happen { my %rsp; - $rsp->{data}->[0] = "Unsupport ulimit return code!\n"; + $rsp->{data}->[0] = "Unsupport ulimit return code!"; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); exit 1; } @@ -3514,21 +3514,21 @@ sub isFdNumExceed #------------------------------------------------------------------------------- =head3 - usage_dsh + usage_dsh puts out dsh usage message Arguments: - None + None Returns: - + Globals: - - + + Error: None - + =cut @@ -3548,7 +3548,7 @@ sub usage_dsh " [-s] [-S ksh | csh] [-t timeout] [-T] [-X environment variables] [-v] [-z]\n"; my $usagemsg6 = " [command_list]\n"; my $usagemsg7 = - "Note:Context always defaults to XCAT unless -C flag is set.\n"; + "Note:Context always defaults to XCAT unless -C flag is set."; my $usagemsg .= $usagemsg1 .= $usagemsg2 .= $usagemsg3 .= $usagemsg4 .= $usagemsg5 .= $usagemsg6 .= $usagemsg7; ### end usage mesage @@ -3560,7 +3560,7 @@ sub usage_dsh } else { - xCAT::MsgUtils->message("I", $usagemsg); + xCAT::MsgUtils->message("I", $usagemsg . "\n"); } return; } @@ -3574,17 +3574,17 @@ sub usage_dsh Arguments: $nodes,$args,$callback,$command,$noderange - These may exist, called from xdsh plugin + These may exist, called from xdsh plugin Returns: - Errors if invalid options or the executed dsh command - + Errors if invalid options or the executed dsh command + Globals: - - + + Error: None - + Example: Comments: @@ -3680,7 +3680,7 @@ sub parse_and_run_dsh { my %rsp; $rsp->{data}->[0] = - "Remote command: $options{'node-rcp'} does not exist or is not executable\n"; + "Remote command: $options{'node-rcp'} does not exist or is not executable"; xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); exit 1; } @@ -3709,8 +3709,8 @@ sub parse_and_run_dsh if (!(@ARGV)) { # no args , an error my %rsp; - $rsp->{data}->[0] = "No command argument provided\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + $rsp->{data}->[0] = "No command argument provided"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); return; } @@ -3720,8 +3720,8 @@ sub parse_and_run_dsh if ($::RUNCMD_RC) { # error from dsh my %rsp; - $rsp->{data}->[0] = "Error from dsh. Return Code = $::RUNCMD_RC\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + $rsp->{data}->[0] = "Error from dsh. Return Code = $::RUNCMD_RC"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); } return (@results); @@ -3730,21 +3730,21 @@ sub parse_and_run_dsh #------------------------------------------------------------------------------- =head3 - usage_dcp + usage_dcp puts out dcp usage message Arguments: - None + None Returns: - + Globals: - - + + Error: None - + =cut @@ -3762,7 +3762,7 @@ sub usage_dcp " [-R] [-t timeout] [-T] [-X environment variables] [-v] \n"; my $usagemsg5 = " source_file... target_path\n"; my $usagemsg6 = - "Note:Context is always defaults to XCAT unless the -C flag is input.\n"; + "Note:Context is always defaults to XCAT unless the -C flag is input."; my $usagemsg .= $usagemsg1 .= $usagemsg2 .= $usagemsg3 .= $usagemsg4 .= $usagemsg5 .= $usagemsg6; @@ -3774,7 +3774,7 @@ sub usage_dcp } else { - xCAT::MsgUtils->message("I", $usagemsg); + xCAT::MsgUtils->message("I", $usagemsg . "\n"); } return; } @@ -3788,17 +3788,17 @@ sub usage_dcp Arguments: $nodes,$args,$callback,$command,$noderange - These may exist, called from xdsh plugin + These may exist, called from xdsh plugin Returns: - Errors if invalid options or the executed dcp command - + Errors if invalid options or the executed dcp command + Globals: - - + + Error: None - + Example: Comments: @@ -3875,7 +3875,7 @@ sub parse_and_run_dcp if ($options{'version'}) { my %rsp; - $rsp->{data}->[0] = "Version 2.0\n"; + $rsp->{data}->[0] = "Version 2.0"; xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); exit(0); } @@ -3894,9 +3894,9 @@ sub parse_and_run_dcp { my %rsp; $rsp->{data}->[0] = - "Remote command: $options{'node-rcp'} does not exist or is not executable\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); - exit 1; + "Remote command: $options{'node-rcp'} does not exist or is not executable"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); + exit; } if ($ENV{'DSH_COPY_FILE_LIST'}) @@ -3908,11 +3908,11 @@ sub parse_and_run_dcp if (@ARGV < 1) { my %rsp; - $rsp->{data}->[0] = "Missing file arguments\n"; - xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); + $rsp->{data}->[0] = "Missing file arguments"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); $rsp->{data}->[0] = $usagemsg; - xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); - exit(1); + xCAT::MsgUtils->message("I", $rsp, $::CALLBACK, 1); + exit; } elsif (@ARGV == 1) @@ -3920,11 +3920,11 @@ sub parse_and_run_dcp if ($options{'pull'}) { my %rsp; - $rsp->{data}->[0] = "Missing target_path\n"; - xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); + $rsp->{data}->[0] = "Missing target_path"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); $rsp->{data}->[0] = $usagemsg; - xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); - exit(1); + xCAT::MsgUtils->message("I", $rsp, $::CALLBACK, 1); + exit; } else @@ -3938,9 +3938,9 @@ sub parse_and_run_dcp { my %rsp; $rsp->{data}->[0] = - "Cannot pull more than one file from targets.\n"; - xCAT::MsgUtils->message("I", $rsp, $::CALLBACK); - exit(1); + "Cannot pull more than one file from targets."; + xCAT::MsgUtils->message("I", $rsp, $::CALLBACK, 1); + exit; } else @@ -3960,8 +3960,8 @@ sub parse_and_run_dcp if ($::RUNCMD_RC) { # error from dcp my %rsp; - $rsp->{data}->[0] = "Error from dsh. Return Code = $::RUNCMD_RC\n"; - xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + $rsp->{data}->[0] = "Error from dsh. Return Code = $::RUNCMD_RC"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK, 1); } return (@results); @@ -3977,17 +3977,17 @@ sub parse_and_run_dcp Arguments: $nodes,$args,$callback,$command,$noderange - These may exist, called from xdsh plugin + These may exist, called from xdsh plugin Returns: - Errors if invalid options or the executed dcp command - + Errors if invalid options or the executed dcp command + Globals: - - + + Error: None - + Example: Comments: @@ -4047,10 +4047,10 @@ sub parse_input_file This subroutine provides a concise interface to run remote command on multiple nodes. Arguments: - $optionRef: - Specifies a hash in which the dsh options are provided + $optionRef: + Specifies a hash in which the dsh options are provided $exitCode: - Normally, if there is an error running the cmd, + Normally, if there is an error running the cmd, it will display the error msg and exit with the cmds exit code, unless exitcode is given one of the following values: @@ -4062,11 +4062,11 @@ sub parse_input_file exit code. number > 0: Display error msg and exit with the given code $refoutput: - if refoutput is true, then the output will be returned as a + if refoutput is true, then the output will be returned as a reference to an array for efficiency. Example: my @outref = xCAT::DSHCLI->runDsh_api(\%options, -2); - + =cut @@ -4153,30 +4153,30 @@ sub runDsh_api =head3 runDcp_api - This subroutine provides a concise interface to run remote command + This subroutine provides a concise interface to run remote command on multiple nodes. Arguments: $optionRef: Specifies a hash in which the dsh options are provided $exitCode: - Normally, if there is an error running the cmd, + Normally, if there is an error running the cmd, it will display the error msg - and exit with the cmds exit code, + and exit with the cmds exit code, unless exitcode is given one of the following values: 0: display error msg, DO NOT exit on error, but set $::RUNCMD_RC to the exit code. - -1: DO NOT display error msg + -1: DO NOT display error msg and DO NOT exit on error, but set $::RUNCMD_RC to the exit code. - -2: DO the default behavior + -2: DO the default behavior (display error msg and exit with cmds exit code. - number > 0: Display error msg and exit with the + number > 0: Display error msg and exit with the given code $refoutput: - if refoutput is true, then the output - will be returned as a reference to + if refoutput is true, then the output + will be returned as a reference to an array for efficiency. Example: my @outref = xCAT::DSHCLI->runDcp_api(\%options, -2); @@ -4281,13 +4281,13 @@ sub runDcp_api Returns: None - + Globals: None - + Error: None - + Example: Comments: diff --git a/perl-xCAT-2.0/xCAT/MsgUtils.pm b/perl-xCAT-2.0/xCAT/MsgUtils.pm index 8a4141f80..8c69ef9c6 100644 --- a/perl-xCAT-2.0/xCAT/MsgUtils.pm +++ b/perl-xCAT-2.0/xCAT/MsgUtils.pm @@ -20,7 +20,7 @@ $::OK = 0; =head2 Package Description -This program module file, supports the xcat messaging and logging +This program module file, supports the xcat messaging and logging @@ -41,43 +41,43 @@ This program module file, supports the xcat messaging and logging #-------------------------------------------------------------------------------- -=head1 Subroutines +=head1 Subroutines =cut =head3 message - Display a msg STDOUT,STDERR or return to callback function. + Display a msg STDOUT,STDERR or return to callback function. If callback routine is provide, the message will be returned to the callback routine. If callback routime is not provide, the message is displayed to STDOUT or STDERR. - + Arguments: The arguments of the message() function are: - + If address of the callback is provided, - then the message will be returned either + then the message will be returned either as data to the client's callback routine or to the xcat daemon or Client.pm ( bypass) for display/logging. - See flags below. + See flags below. If address of the callback is not provide, then - the message will be displayed to STDERR or STDOUT or + the message will be displayed to STDERR or STDOUT or added to SYSLOG. See flags below. For compatibility with existing code, the message routine will move the data into the appropriate callback structure, if required. See example below, if the input to the message routine - has the "data" structure filled in for an error message, then - the message routine will move the $rsp->{data}->[0] to + has the "data" structure filled in for an error message, then + the message routine will move the $rsp->{data}->[0] to $rsp->{error}->[0]. This will allow xcatd/Client.pm will process all but "data" messages. - The current client code should not have to change. + The current client code should not have to change. my %rsp; $rsp->{data}->[0] = "Job did not run. \n"; @@ -86,41 +86,41 @@ This program module file, supports the xcat messaging and logging Here the message routine will move $rsp->{data}->[0] to $rsp->{error}->[0], to match the "E"message code. Note the message - routine will only check for the data to either exist in - $rsp->{error}->[0] already, or to exist in $rsp->{data}->[0]. - + routine will only check for the data to either exist in + $rsp->{error}->[0] already, or to exist in $rsp->{data}->[0]. + Here's the meaning of the 1st character, if a callback specified: - D - DATA this is returned to the client callback routine - E - error this is displayed/logged by daemon/Client.pm. + D - DATA this is returned to the client callback routine + E - error this is displayed/logged by daemon/Client.pm. I - informational this is displayed/logged by daemon/Client.pm. - S - Message will be logged to syslog ( severe error) + S - Message will be logged to syslog ( severe error) syslog facily (local4) and priority (err) will be used. See /etc/syslog.conf file for the destination of the messages. Note S can be combined with other flags for example SE logs message to syslog to also display the - message by daemon/ Client.pm. + message by daemon/ Client.pm. V - verbose. This flag is not valid, the calling routine should check for verbose mode before calling the message routine and only use the I flag for the message. - If V flag is detected, it will be changed to an I flag. - W - warning this is displayed/logged by daemon/Client.pm. + If V flag is detected, it will be changed to an I flag. + W - warning this is displayed/logged by daemon/Client.pm. Here's the meaning of the 1st character, if no callback specified: - D - DATA goes to STDOUT + D - DATA goes to STDOUT E - error. This type of message will be sent to STDERR. - I - informational goes to STDOUT - S - Message will be logged to syslog ( severe error) + I - informational goes to STDOUT + S - Message will be logged to syslog ( severe error) Note S can be combined with other flags for example - SE logs message to syslog and is sent to STDERR. + SE logs message to syslog and is sent to STDERR. V - verbose. This flag is not valid, the calling routine should check for verbose mode before calling the message routine and only use the I flag for the message. - If V flag is detected, it will be changed to an I flag. - W - warning goes to STDOUT. + If V flag is detected, it will be changed to an I flag. + W - warning goes to STDOUT. Returns: none @@ -130,12 +130,12 @@ This program module file, supports the xcat messaging and logging Example: - Use with no callback + Use with no callback xCAT::MsgUtils->message('E', "Operation $value1 failed\n"); xCAT::MsgUtils->message('S', "Host $host not responding\n"); xCAT::MsgUtils->message('SI', "Host $host not responding\n"); - Use with callback + Use with callback my %rsp; $rsp->{data}->[0] = "Job did not run. \n"; xCAT::MsgUtils->message("D", $rsp, $::CALLBACK); @@ -169,7 +169,7 @@ This program module file, supports the xcat messaging and logging Comments: - + Returns: none @@ -188,6 +188,7 @@ sub message my $sev = shift; my $rsp = shift; my $call_back = shift; # optional + my $exitcode = shift; # optional # should be I, D, E, S, W # or S(I, D, E, S, W) @@ -209,44 +210,36 @@ sub message $sev = "SI"; } - # check that correct structure is filled in - # and move to correct structure. If the data is not in the + # Check that correct structure is filled in. If the data is not in the # structure corresponding to the $sev, then look for it in "data" - if ($call_back) - { # callback routine provided - if (($sev eq 'I') || ($sev eq 'SI')) - { - if (!($rsp->{info}->[0])) # no info data - { # no error data - $rsp->{info}->[0] = $rsp->{data}->[0]; - - # $rsp->{data}->[0] = ""; + #TODO: this is not really right for a couple reasons: 1) all the fields in the + # response structure are arrays, so can handle multiple lines of text. We + # should not just be check the 0th element. 2) a cmd may have both error + # text and data text. 3) this message() function should just take in a plain + # string and put it in the correct place based on the severity. + if ($call_back) { # callback routine provided + my $sevkey; + if ($sev =~ /I/) { $sevkey = 'info'; } + if ($sev =~ /W/) { $sevkey = 'warning'; } + if ($sev =~ /E/) { + $sevkey = 'error'; + if (!defined($exitcode)) { $exitcode = 1; } # default to something non-zero + } + if (defined($sevkey)) { + if (!defined ($rsp->{$sevkey}) || !scalar(@{$rsp->{$sevkey}})) { # did not pass the text in in the severity-specific field + if (defined ($rsp->{data}) && scalar(@{$rsp->{data}})) { + push @{$rsp->{$sevkey}}, shift @{$rsp->{data}}; # assume they passed in the text in the data field instead + } } - } - if (($sev eq 'E') || ($sev eq 'S') || ($sev eq 'SE')) - { - if (!($rsp->{error}->[0])) # no error data - { # no error data - $rsp->{error}->[0] = $rsp->{data}->[0]; + } + if (!defined ($rsp->{$sevkey}) || !scalar(@{$rsp->{$sevkey}})) { return; } # if still nothing in the array, there is nothing to print out - # $rsp->{data}->[0] = ""; - } - } - if (($sev eq 'W') || ($sev eq 'SW')) - { - if (!($rsp->{warning}->[0])) # no warning data - { # no error data - $rsp->{warning}->[0] = $rsp->{data}->[0]; - - # $rsp->{data}->[0] = ""; - } - } - - if ($sev ne 'S') + if ($sev ne 'S') # if sev is anything but only-syslog, print the msg { # not just syslog - $call_back->($rsp); # send message to daemon/Client.pm unless - # data structure which is output by the commands - # callback routine. + if ($exitcode) { $rsp->{errorcode}->[0] = $exitcode; } + $call_back->($rsp); # send message to daemon/Client.pm + shift @{$rsp->{$sevkey}}; # clear out the rsp structure in case they use it again + if ($exitcode) { shift @{$rsp->{errorcode}}; } } } else # no callback provided diff --git a/xCAT-client-2.0/bin/xcatDBcmds b/xCAT-client-2.0/bin/xcatDBcmds index c8ae9b71b..4bd540a5d 100755 --- a/xCAT-client-2.0/bin/xcatDBcmds +++ b/xCAT-client-2.0/bin/xcatDBcmds @@ -1,4 +1,5 @@ -#!/usr/bin/env perl +#!/usr/bin/perl +# !/usr/bin/env perl # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html BEGIN { @@ -59,15 +60,15 @@ foreach (@ARGV) push(@{$cmdref->{arg}}, $_); } -# Is it necessary to pass the node range through the client-server path ?? +# Is it necessary to pass the node range through the client-server path ?? # -# !!!!! +# !!!!! # -# BUT - also want to pass in a list of object definitions that are +# BUT - also want to pass in a list of object definitions that are # not noderanges -# -# -# In any case - this doesn't work for mkdef & chdef because we may be +# +# +# In any case - this doesn't work for mkdef & chdef because we may be # creating the node definition for the first time # #if (!($bname =~ /mkdef/)) @@ -115,7 +116,7 @@ if (0) my $arg = shift(@ARGV); if (!($arg =~ /=/)) { - # only set the noderange if it was a type of node or the type + # only set the noderange if it was a type of node or the type # wasn't specified. if (!$::opt_t || ($::opt_t eq 'node')) { $cmdref->{noderange}->[0] = $arg; @@ -125,141 +126,5 @@ if (0) } -xCAT::Client::submit_request($cmdref, \&handle_response); - -exit 0; - -# may want to modify handle_response at some point!!!!!!! - -########################################## -# handle_response is the callback that is -# invoked to print out the data returned by -# the plugin. -# -# Format of the response hash: -# {data => [ 'data str1', 'data str2', '...' ] } -# -# Results are printed as: -# data str1 -# data str2 -# -# or: -# {data => [ {desc => [ 'desc1' ], -# contents => [ 'contents1' ] }, -# {desc => [ 'desc2 ], -# contents => [ 'contents2' ] } -# : -# ] } -# NOTE: In this format, only the data array can have more than one -# element. All other arrays are assumed to be a single element. -# Results are printed as: -# desc1: contents1 -# desc2: contents2 -# -# or: -# {node => [ {name => ['node1'], -# data => [ {desc => [ 'node1 desc' ], -# contents => [ 'node1 contents' ] } ] }, -# {name => ['node2'], -# data => [ {desc => [ 'node2 desc' ], -# contents => [ 'node2 contents' ] } ] }, -# : -# ] } -# NOTE: Only the node array can have more than one element. -# All other arrays are assumed to be a single element. -# -# This was generated from the corresponding HTML: -# <xcatrequest> -# <node> -# <name>node1</name> -# <data> -# <desc>node1 desc</desc> -# <contents>node1 contents</contents> -# </data> -# </node> -# <node> -# <name>node2</name> -# <data> -# <desc>node2 desc</desc> -# <contents>node2 contents</contents> -# </data> -# </node> -# </xcatrequest> -# -# Results are printed as: -# node_name: desc: contents -########################################## -sub handle_response -{ - my $rsp = shift; - - # Handle {node} structure - if ($rsp->{node}) - { - my $nodes = ($rsp->{node}); - my $node; - foreach $node (@$nodes) - { - my $desc = $node->{name}->[0]; - if ($node->{data}) - { - if (ref(\($node->{data}->[0])) eq 'SCALAR') - { - $desc = $desc . ": " . $node->{data}->[0]; - } - else - { - if ($node->{data}->[0]->{desc}) - { - $desc = $desc . ": " . $node->{data}->[0]->{desc}->[0]; - } - if ($node->{data}->[0]->{contents}) - { - $desc = "$desc: " . $node->{data}->[0]->{contents}->[0]; - } - } - } - if ($desc) - { - print "$desc\n"; - } - } - } - - # Handle {data} structure with no nodes - if ($rsp->{data}) - { - my $data = ($rsp->{data}); - my $data_entry; - foreach $data_entry (@$data) - { - my $desc; - if (ref(\($data_entry)) eq 'SCALAR') - { - $desc = $data_entry; - } - else - { - if ($data_entry->{desc}) - { - $desc = $data_entry->{desc}->[0]; - } - if ($data_entry->{contents}) - { - if ($desc) - { - $desc = "$desc: " . $data_entry->{contents}->[0]; - } - else - { - $desc = $data_entry->{contents}->[0]; - } - } - } - if ($desc) - { - print "$desc\n"; - } - } - } -} +xCAT::Client::submit_request($cmdref,\&xCAT::Client::handle_response); +exit $xCAT::Client::EXITCODE; diff --git a/xCAT-client-2.0/bin/xdsh b/xCAT-client-2.0/bin/xdsh index cfce63fe7..09e095634 100644 --- a/xCAT-client-2.0/bin/xdsh +++ b/xCAT-client-2.0/bin/xdsh @@ -1,18 +1,17 @@ -#!/usr/bin/env perl +#!/usr/bin/perl +# !/usr/bin/env perl # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html BEGIN { $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; } use lib "$::XCATROOT/lib/perl"; -use IO::Socket::SSL; -use IO::Socket::INET; use File::Basename; -use Data::Dumper; +#use Data::Dumper; use Getopt::Long; use xCAT::MsgUtils; use xCAT::DSHCLI; -use xCAT::Client submit_request; +use xCAT::Client; my $bname = basename($0); #----------------------------------------------------------------------------- @@ -26,11 +25,11 @@ This program is the client interface for xdsh/xdcp. This is the interface to for xdsh/xdsp The command can run in client/server mode (default) or in bypass mode - where it does not use the xcat daemon xcatd. + where it does not use the xcat daemon xcatd. Bypass mode is useful, when executing the command on the Management Server - and in particular if you want to run as a non-root id. + and in particular if you want to run as a non-root id. Call parse_args to verify mode (client/server or bypass) - and whether to use Env Variables + and whether to use Env Variables Build hash and submit request See man page for options @@ -39,8 +38,6 @@ This program is the client interface for xdsh/xdcp. #----------------------------------------------------------------------------- # Main -my $rc = 0; - # report unsupported dsh exports &check_invalid_exports; @@ -123,17 +120,17 @@ if (!($::CONTEXT_SET)) } } -xCAT::Client::submit_request($cmdref, \&handle_response); -exit $rc; +xCAT::Client::submit_request($cmdref,\&xCAT::Client::handle_response); +exit $xCAT::Client::EXITCODE; #----------------------------------------------------------------------------- =head3 parse_args_xdsh - + Parses for dsh input Check if the command ask for help and display usage Need to check only for the -X flag - Need to check -B flag to determine mode + Need to check -B flag to determine mode =cut @@ -187,7 +184,7 @@ sub parse_args_xdsh xCAT::DSHCLI->usage_dsh; exit 0; } - if ($options{'bypass'}) + if ($options{'bypass'} || $options{'ssh-setup'}) # must force bypass mode for -K, so it can prompt user for node pw { $ENV{XCATBYPASS} = "yes"; # bypass xcatd } @@ -226,11 +223,11 @@ sub parse_args_xdsh #----------------------------------------------------------------------------- =head3 parse_args_xdcp - + Parses for dcp input Check if the command ask for help and display usage Need to check -X flag to determine how to set Environment Variables - Need to check -B flag to determine mode + Need to check -B flag to determine mode =cut @@ -370,149 +367,3 @@ sub check_invalid_exports " DSH_REPORT is set but is not supported. It will be ignored.\n"); } } - -#----------------------------------------------------------------------------- - -=head3 handle_response - handle_response is the callback that is - invoked to print out the data returned by - the plugin. - - Format of the response hash: - {data => [ 'data str1', 'data str2', '...' ] } - - Results are printed as: - data str1 - data str2 - - or: - {data => [ {desc => [ 'desc1' ], - contents => [ 'contents1' ] }, - {desc => [ 'desc2 ], - contents => [ 'contents2' ] } - : - ] } - NOTE: In this format, only the data array can have more than one - element. All other arrays are assumed to be a single element. - Results are printed as: - desc1: contents1 - desc2: contents2 - - or: - {node => [ {name => ['node1'], - data => [ {desc => [ 'node1 desc' ], - contents => [ 'node1 contents' ] } ] }, - {name => ['node2'], - data => [ {desc => [ 'node2 desc' ], - contents => [ 'node2 contents' ] } ] }, - : - ] } - NOTE: Only the node array can have more than one element. - All other arrays are assumed to be a single element. - - This was generated from the corresponding HTML: - <xcatrequest> - <node> - <name>node1</name> - <data> - <desc>node1 desc</desc> - <contents>node1 contents</contents> - </data> - </node> - <node> - <name>node2</name> - <data> - <desc>node2 desc</desc> - <contents>node2 contents</contents> - </data> - </node> - </xcatrequest> - - Results are printed as: - node_name: desc: contents -=cut - -#----------------------------------------------------------------------------- -sub handle_response -{ - my $rsp = shift; - - # Handle {node} structure - if ($rsp->{errorcode}) - { - foreach my $ecode (@{$rsp->{errorcode}}) - { - $exitcode |= $ecode; - } - } - - # Handle {node} structure - if ($rsp->{node}) - { - my $nodes = ($rsp->{node}); - my $node; - foreach $node (@$nodes) - { - my $desc = $node->{name}->[0]; - if ($node->{data}) - { - if (ref(\($node->{data}->[0])) eq 'SCALAR') - { - $desc = $desc . ": " . $node->{data}->[0]; - } - else - { - if ($node->{data}->[0]->{desc}) - { - $desc = $desc . ": " . $node->{data}->[0]->{desc}->[0]; - } - if ($node->{data}->[0]->{contents}) - { - $desc = "$desc: " . $node->{data}->[0]->{contents}->[0]; - } - } - } - if ($desc) - { - print "$desc\n"; - } - } - } - - # Handle {data} structure with no nodes - if ($rsp->{data}) - { - my $data = ($rsp->{data}); - my $data_entry; - foreach $data_entry (@$data) - { - my $desc; - if (ref(\($data_entry)) eq 'SCALAR') - { - $desc = $data_entry; - } - else - { - if ($data_entry->{desc}) - { - $desc = $data_entry->{desc}->[0]; - } - if ($data_entry->{contents}) - { - if ($desc) - { - $desc = "$desc: " . $data_entry->{contents}->[0]; - } - else - { - $desc = $data_entry->{contents}->[0]; - } - } - } - if ($desc) - { - print "$desc\n"; - } - } - } -} diff --git a/xCAT-client-2.0/pods/man1/tabdump.1.pod b/xCAT-client-2.0/pods/man1/tabdump.1.pod index 85e32e602..1e717791f 100644 --- a/xCAT-client-2.0/pods/man1/tabdump.1.pod +++ b/xCAT-client-2.0/pods/man1/tabdump.1.pod @@ -28,11 +28,16 @@ B<-?|-h|--help> Display usage message. 1. To display the contents of the site table: -I<tabdump site> + tabdump site 2. To see what tables exist in the xCAT database: -I<tabdump> + tabdump + +3. To see what tables exist in the xCAT database: + + mkdir -p /tmp/xcatdb.backup + for i in `tabdump`;do echo "Dumping $i..."; tabdump $i > /tmp/xcatdb.backup/$i.csv; done =head1 FILES @@ -40,6 +45,4 @@ I<tabdump> =head1 NOTES -This command is part of the xCAT software product. - - +This command is part of the xCAT software product. \ No newline at end of file diff --git a/xCAT-client-2.0/pods/man1/tabrestore.1.pod b/xCAT-client-2.0/pods/man1/tabrestore.1.pod index d729207bb..f8876938c 100644 --- a/xCAT-client-2.0/pods/man1/tabrestore.1.pod +++ b/xCAT-client-2.0/pods/man1/tabrestore.1.pod @@ -32,12 +32,17 @@ B<-?|-h|--help> Display usage message. 1. To put rows into the mp table: -I<tabrestore mp.csv> + tabrestore mp.csv The file mp.csv could contain something like: -#node,mpa,id,comments,disable -"blade","|\D+(\d+)|amm(($1-1)/14+1)|","|\D+(\d+)|(($1-1)%14+1)|",, + #node,mpa,id,comments,disable + "blade","|\D+(\d+)|amm(($1-1)/14+1)|","|\D+(\d+)|(($1-1)%14+1)|",, + +2. To restore database tables that were dumped with tabdump: + + cd /tmp/xcatdb.backup + for i in *.csv;do echo "Restoring $i..."; tabrestore $i; done =head1 FILES @@ -45,6 +50,4 @@ The file mp.csv could contain something like: =head1 NOTES -This command is part of the xCAT software product. - - +This command is part of the xCAT software product. \ No newline at end of file diff --git a/xCAT-client-2.0/share/man/man1/tabdump.1 b/xCAT-client-2.0/share/man/man1/tabdump.1 index b501b90c1..1bc04be8f 100644 --- a/xCAT-client-2.0/share/man/man1/tabdump.1 +++ b/xCAT-client-2.0/share/man/man1/tabdump.1 @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title "TABDUMP.1 1" -.TH TABDUMP.1 1 "2008-02-13" "perl v5.8.8" "User Contributed Perl Documentation" +.TH TABDUMP.1 1 "2008-02-18" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" \&\fBtabdump\fR \- display a database table in csv format. .SH "SYNOPSIS" @@ -154,14 +154,25 @@ tables will be displayed. .IX Header "EXAMPLES" 1. To display the contents of the site table: .PP -\&\fItabdump site\fR +.Vb 1 +\& tabdump site +.Ve .PP 2. To see what tables exist in the xCAT database: .PP -\&\fItabdump\fR +.Vb 1 +\& tabdump +.Ve +.PP +3. To see what tables exist in the xCAT database: +.PP +.Vb 2 +\& mkdir -p /tmp/xcatdb.backup +\& for i in `tabdump`;do echo "Dumping $i..."; tabdump $i > /tmp/xcatdb.backup/$i.csv; done +.Ve .SH "FILES" .IX Header "FILES" /opt/xcat/sbin/tabdump .SH "NOTES" .IX Header "NOTES" -This command is part of the xCAT software product. +This command is part of the xCAT software product. \ No newline at end of file diff --git a/xCAT-client-2.0/share/man/man1/tabrestore.1 b/xCAT-client-2.0/share/man/man1/tabrestore.1 index 5f5041e9c..4bbed2ad1 100644 --- a/xCAT-client-2.0/share/man/man1/tabrestore.1 +++ b/xCAT-client-2.0/share/man/man1/tabrestore.1 @@ -129,7 +129,7 @@ .\" ======================================================================== .\" .IX Title "TABRESTORE.1 1" -.TH TABRESTORE.1 1 "2008-02-14" "perl v5.8.8" "User Contributed Perl Documentation" +.TH TABRESTORE.1 1 "2008-02-18" "perl v5.8.8" "User Contributed Perl Documentation" .SH "NAME" \&\fBtabrestore\fR \- replaces the contents of an xCAT database table with the contents in a csv file. .SH "SYNOPSIS" @@ -158,15 +158,26 @@ into the xCAT database. .IX Header "EXAMPLES" 1. To put rows into the mp table: .PP -\&\fItabrestore mp.csv\fR +.Vb 1 +\& tabrestore mp.csv +.Ve .PP The file mp.csv could contain something like: .PP -#node,mpa,id,comments,disable -\&\*(L"blade\*(R",\*(L"|\eD+(\ed+)|amm(($1\-1)/14+1)|\*(R",\*(L"|\eD+(\ed+)|(($1\-1)%14+1)|\*(R",, +.Vb 2 +\& #node,mpa,id,comments,disable +\& "blade","|\eD+(\ed+)|amm(($1-1)/14+1)|","|\eD+(\ed+)|(($1-1)%14+1)|",, +.Ve +.PP +2. To restore database tables that were dumped with tabdump: +.PP +.Vb 2 +\& cd /tmp/xcatdb.backup +\& for i in *.csv;do echo "Restoring $i..."; tabrestore $i; done +.Ve .SH "FILES" .IX Header "FILES" /opt/xcat/sbin/tabrestore .SH "NOTES" .IX Header "NOTES" -This command is part of the xCAT software product. +This command is part of the xCAT software product. \ No newline at end of file diff --git a/xCAT-server-2.0/lib/xcat/plugins/xdsh.pm b/xCAT-server-2.0/lib/xcat/plugins/xdsh.pm index fca109bf8..d91c861aa 100644 --- a/xCAT-server-2.0/lib/xcat/plugins/xdsh.pm +++ b/xCAT-server-2.0/lib/xcat/plugins/xdsh.pm @@ -1,7 +1,7 @@ # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html #------------------------------------------------------- -=head1 +=head1 xCAT plugin package to handle xdsh Supported command: @@ -23,7 +23,7 @@ require xCAT::DSHCLI; #------------------------------------------------------- -=head3 handled_commands +=head3 handled_commands Return list of commands handled by this plugin @@ -41,7 +41,7 @@ sub handled_commands #------------------------------------------------------- -=head3 process_request +=head3 process_request Process the command @@ -59,22 +59,10 @@ sub process_request my $envs = $request->{env}; my %rsp; - # get Environment Variables - my $outref = []; - foreach my $envar (@{$request->{env}}) - { - my $cmd = "export "; - $cmd .= $envar; - $cmd .= ";"; - @$outref = `$cmd`; - if ($? > 0) - { - my %rsp; - $rsp->{data}->[0] = "Error running command: $cmd\n"; - xCAT::MsgUtils->message("E", $rsp, $callback); - return 1; - - } + # get the Environment Variables and set them in the current environment + foreach my $envar (@{$request->{env}}) { + my ($var, $value) = split(/=/, $envar, 2); + $ENV{$var} = $value; } if ($command eq "xdsh") { @@ -91,18 +79,18 @@ sub process_request { my %rsp; $rsp->{data}->[0] = - "Unknown command $command. Cannot process the command\n"; - xCAT::MsgUtils->message("E", $rsp, $callback); - return 1; + "Unknown command $command. Cannot process the command."; + xCAT::MsgUtils->message("E", $rsp, $callback, 1); + return; } } } #------------------------------------------------------- -=head3 xdsh +=head3 xdsh - Parses Builds and runs the dsh + Parses Builds and runs the dsh =cut @@ -116,25 +104,18 @@ sub xdsh @local_results = xCAT::DSHCLI->parse_and_run_dsh($nodes, $args, $callback, $command, $noderange); - my %rsp; - my $i = 0; - ## process return data - foreach my $line (@local_results) - { - $rsp->{data}->[$i] = $line; - $i++; - } + push @{$rsp->{data}}, @local_results; xCAT::MsgUtils->message("I", $rsp, $callback); - return 0; + return; } #------------------------------------------------------- -=head3 xdcp +=head3 xdcp - Parses, Builds and runs the dcp command + Parses, Builds and runs the dcp command =cut @@ -159,6 +140,6 @@ sub xdcp xCAT::MsgUtils->message("I", $rsp, $callback); - return 0; + return; }