[pve-devel] applied: [PATCH pve-manager v2] pvesh: fix bug #1942 - add standard options conditional
Thomas Lamprecht
t.lamprecht at proxmox.com
Tue Oct 16 11:53:26 CEST 2018
On 10/16/18 10:55 AM, Dietmar Maurer wrote:
> Do not add/extract standard options if the method itself defined properties
> using the same names (like 'quiet').
>
> Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
> ---
>
> Changes in v2:
>
> - remove unused code (as suggested by David)
>
applied, thanks!
> 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 <api_path>.",
> 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 <api_path>.",
> 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 <api_path>.",
> 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 <api_path>.",
> 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 <api_path>.",
> 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 {
>
More information about the pve-devel
mailing list