[pve-devel] [PATCH manager] fix #1922: let the target node handle the output formatting

Dominik Csapak d.csapak at proxmox.com
Tue Jan 22 11:58:10 CET 2019


we tried to only get the data and format the output locally,
but this fails when the data is not json
(e.g. all error messages, worker where we continuously print output, etc.)

so let the target node handle the output and only collect the exit code
which we mirror locally (also let ssh/run_command handle stdout/stderr)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/CLI/pvesh.pm | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/PVE/CLI/pvesh.pm b/PVE/CLI/pvesh.pm
index 9b8e3245..b180700f 100755
--- a/PVE/CLI/pvesh.pm
+++ b/PVE/CLI/pvesh.pm
@@ -105,24 +105,17 @@ sub proxy_handler {
 
     my $args = [];
     foreach my $key (keys %$param) {
-	next if $key eq 'quiet' || $key eq 'output-format'; # just to  be sure
 	push @$args, "--$key", $param->{$key};
     }
 
     my $remcmd = ['ssh', '-o', 'BatchMode=yes', "root\@$remip",
-		  'pvesh', '--noproxy', $cmd, $path,
-		  '--output-format', 'json'];
+		  'pvesh', '--noproxy', $cmd, $path];
 
     if (scalar(@$args)) {
 	my $cmdargs = [String::ShellQuote::shell_quote(@$args)];
 	push @$remcmd, @$cmdargs;
     }
-
-    my $json = '';
-    PVE::Tools::run_command($remcmd, errmsg => "proxy handler failed",
-			    outfunc => sub { $json .= shift });
-
-    return decode_json($json);
+    return PVE::Tools::run_command($remcmd, noerr => 1, keeplocale => 1);
 }
 
 sub extract_children {
@@ -290,10 +283,7 @@ sub call_api_method {
     my $path = PVE::Tools::extract_param($param, 'api_path');
     die "missing API path\n" if !defined($path);
 
-    my $stdopts =  $extract_std_options ?
-	PVE::RESTHandler::extract_standard_output_properties($param) : {};
-
-    $opt_nooutput = 1 if $stdopts->{quiet};
+    my $stdopts;
 
     my $uri_param = {};
     my ($handler, $info) = PVE::API2->find_handler($method, $path, $uri_param);
@@ -305,7 +295,11 @@ sub call_api_method {
     my ($node, $remip) = check_proxyto($info, $uri_param);
     if ($node) {
 	$data = proxy_handler($node, $remip, $path, $cmd, $param);
+	exit $data;
     } else {
+	$stdopts = $extract_std_options ?
+	    PVE::RESTHandler::extract_standard_output_properties($param) : {};
+	$opt_nooutput = 1 if $stdopts->{quiet};
 	foreach my $p (keys %$uri_param) {
 	    $param->{$p} = $uri_param->{$p};
 	}
@@ -333,7 +327,7 @@ __PACKAGE__->register_method ({
 
 	my $path = PVE::Tools::extract_param($param, 'api_path');
 
-	my $stdopts =  PVE::RESTHandler::extract_standard_output_properties($param);
+	my $stdopts;
 
 	my $uri_param = {};
 	my ($handler, $info) = PVE::API2->find_handler('GET', $path, $uri_param);
@@ -349,7 +343,10 @@ __PACKAGE__->register_method ({
 	my ($node, $remip) = check_proxyto($info, $uri_param);
 	if ($node) {
 	    $res = proxy_handler($node, $remip, $path, 'ls', $param);
+	    exit $res;
 	} else {
+	    $stdopts =  PVE::RESTHandler::extract_standard_output_properties($param);
+
 	    foreach my $p (keys %$uri_param) {
 		$param->{$p} = $uri_param->{$p};
 	    }
-- 
2.11.0





More information about the pve-devel mailing list