[pve-devel] [PATCH 5/7] pending api : change structure from array to nested objects

Alexandre Derumier aderumier at odiso.com
Fri Jan 2 15:16:02 CET 2015


fixme : parse digest

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm |   39 +++++++--------------------------------
 1 file changed, 7 insertions(+), 32 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 328a82c..e39e59b 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -689,26 +689,7 @@ __PACKAGE__->register_method({
 	},
     },
     returns => {
-	type => "array",
-	items => {
-	    type => "object",
-	    properties => {
-		key => {
-		    description => "Configuration option name.",
-		    type => 'string',
-		},
-		value => {
-		    description => "Current value.",
-		    type => 'string',
-		    optional => 1,
-		},
-		delete => {
-		    description => "Indicated a pending delete request.",
-		    type => 'boolean',
-		    optional => 1,
-		},
-	    },
-	},
+        type => "object",
     },
     code => sub {
 	my ($param) = @_;
@@ -720,33 +701,27 @@ __PACKAGE__->register_method({
 	    $pending_delete_hash->{$opt} = 1;
 	}
  
-	my $res = [];
+        my $res = {};
 
 	foreach my $opt (keys $conf) {
 	    next if ref($conf->{$opt});
-	    my $item = { key => $opt };
-	    $item->{value} = $conf->{$opt} if defined($conf->{$opt});
-	    $item->{pending} = $conf->{pending}->{$opt} if defined($conf->{pending}->{$opt});
-	    $item->{delete} = 1 if $pending_delete_hash->{$opt};
-	    push @$res, $item;
+	    $res->{$opt}->{value} = $conf->{$opt} if defined($conf->{$opt});
+	    $res->{$opt}->{pending} = $conf->{pending}->{$opt} if defined($conf->{pending}->{$opt});
+	    $res->{$opt}->{delete} = 1 if $pending_delete_hash->{$opt};
 	}
 
 	foreach my $opt (keys $conf->{pending}) {
 	    next if $opt eq 'delete';
 	    next if ref($conf->{pending}->{$opt}); # just to be sure
 	    next if $conf->{$opt};
-	    my $item = { key => $opt };
-	    $item->{pending} = $conf->{pending}->{$opt};
-	    push @$res, $item;
+	    $res->{$opt}->{pending} = $conf->{pending}->{$opt};
 	}
 
 	foreach my $opt (PVE::Tools::split_list($conf->{pending}->{delete})) {
 	    next if $conf->{pending}->{$opt}; # just to be sure
 	    next if $conf->{$opt};
-	    my $item = { key => $opt, delete => 1};
-	    push @$res, $item;
+	    $res->{$opt}->{delete} = 1;
 	}
-
 	return $res;
     }});
 
-- 
1.7.10.4




More information about the pve-devel mailing list