[pve-devel] [PATCH qemu-server] api: add option to get pending config returned as object instead of an array

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Jun 24 10:20:41 CEST 2020


a bit of a rationale would be nice ;) isn't this just a simple map 
transformation that can be done client-side?

my $hash = { map { my $key = delete $_->{key}; return ($key => $_); } @$array };

or in whatever language you need. filtering/sorting/limiting server-side 
makes sense for some calls that might return a lot of data otherwise, 
but I don't think adapting all API calls to represent data with 
different structures but identical content is a good idea.

(not that I am too happy that we have so many 'array of object with key 
property' return values to accomodate ExtJS, when our backend and API 
usually carries the key as key and not part of the object)

On May 20, 2020 2:23 pm, Tim Marx wrote:
> Signed-off-by: Tim Marx <t.marx at proxmox.com>
> ---
>  PVE/API2/Qemu.pm | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index fd51bf3..0b31f53 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -940,14 +940,20 @@ __PACKAGE__->register_method({
>  	check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
>      },
>      parameters => {
> -	additionalProperties => 0,
>  	properties => {
>  	    node => get_standard_option('pve-node'),
>  	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
> +	    object => {
> +		description => "In this case the root element is an object instead of an array.".
> +			       "The key property of the items will be extracted and used as the root object keys.",
> +		optional => 1,
> +		default => 0,
> +		type => 'boolean',
> +	    },
>  	},
>      },
>      returns => {
> -	type => "array",
> +	type => [ "array", "object"],
>  	items => {
>  	    type => "object",
>  	    properties => {
> @@ -985,8 +991,7 @@ __PACKAGE__->register_method({
>  
>  	$conf->{cipassword} = '**********' if defined($conf->{cipassword});
>  	$conf->{pending}->{cipassword} = '********** ' if defined($conf->{pending}->{cipassword});
> -
> -	return PVE::GuestHelpers::config_with_pending_array($conf, $pending_delete_hash);
> +	return PVE::GuestHelpers::config_with_pending($conf, $pending_delete_hash, $param->{object});
>     }});
>  
>  # POST/PUT {vmid}/config implementation
> -- 
> 2.20.1
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 




More information about the pve-devel mailing list