From ddc9c56c4dd47d59edf029eea1a0a5fcb92b16a7 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 16 Oct 2018 10:55:05 +0200 Subject: [PATCH] pvesh: fix bug #1942 - add standard options conditional Do not add/extract standard options if the method itself defined properties using the same names (like 'quiet'). Signed-off-by: Dietmar Maurer --- PVE/CLI/pvesh.pm | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/PVE/CLI/pvesh.pm b/PVE/CLI/pvesh.pm index ccfb5c20..41e27a00 100755 --- a/PVE/CLI/pvesh.pm +++ b/PVE/CLI/pvesh.pm @@ -263,6 +263,21 @@ $path_properties->{noproxy} = { optional => 1, }; +my $extract_std_options = 1; + +my $cond_add_standard_output_properties = sub { + my ($props) = @_; + + foreach my $opt (keys %$PVE::RESTHandler::standard_output_options) { + if (defined($props->{$opt})) { + $extract_std_options = 0; + return $props; + } + } + + return PVE::RESTHandler::add_standard_output_properties($props); +}; + sub call_api_method { my ($cmd, $param) = @_; @@ -271,7 +286,8 @@ sub call_api_method { my $path = PVE::Tools::extract_param($param, 'api_path'); die "missing API path\n" if !defined($path); - my $stdopts = PVE::RESTHandler::extract_standard_output_properties($param); + my $stdopts = $extract_std_options ? + PVE::RESTHandler::extract_standard_output_properties($param) : {}; $opt_nooutput = 1 if $stdopts->{quiet}; @@ -305,7 +321,7 @@ __PACKAGE__->register_method ({ description => "List child objects on .", parameters => { additionalProperties => 0, - properties => PVE::RESTHandler::add_standard_output_properties($path_properties), + properties => $cond_add_standard_output_properties->($path_properties), }, returns => { type => 'null' }, code => sub { @@ -361,7 +377,7 @@ __PACKAGE__->register_method ({ description => "Call API GET on .", parameters => { additionalProperties => 0, - properties => PVE::RESTHandler::add_standard_output_properties($path_properties), + properties => $cond_add_standard_output_properties->($path_properties), }, returns => { type => 'null' }, code => sub { @@ -379,7 +395,7 @@ __PACKAGE__->register_method ({ description => "Call API PUT on .", parameters => { additionalProperties => 0, - properties => PVE::RESTHandler::add_standard_output_properties($path_properties), + properties => $cond_add_standard_output_properties->($path_properties), }, returns => { type => 'null' }, code => sub { @@ -397,7 +413,7 @@ __PACKAGE__->register_method ({ description => "Call API POST on .", parameters => { additionalProperties => 0, - properties => PVE::RESTHandler::add_standard_output_properties($path_properties), + properties => $cond_add_standard_output_properties->($path_properties), }, returns => { type => 'null' }, code => sub { @@ -415,7 +431,7 @@ __PACKAGE__->register_method ({ description => "Call API DELETE on .", parameters => { additionalProperties => 0, - properties => PVE::RESTHandler::add_standard_output_properties($path_properties), + properties => $cond_add_standard_output_properties->($path_properties), }, returns => { type => 'null' }, code => sub {