[pve-devel] [PATCH 2/7] add optionnal current param to config api

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


config api return by default the pending config, like this it don't break current behaviour

Add an optionnal current param to get to current running config

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

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index fb36ce8..328a82c 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -624,7 +624,7 @@ __PACKAGE__->register_method({
     path => '{vmid}/config',
     method => 'GET',
     proxyto => 'node',
-    description => "Get current virtual machine configuration. This does not include pending configuration changes (see 'pending' API).",
+    description => "Get pending virtual machine configuration",
     permissions => {
 	check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
     },
@@ -633,6 +633,12 @@ __PACKAGE__->register_method({
 	properties => {
 	    node => get_standard_option('pve-node'),
 	    vmid => get_standard_option('pve-vmid'),
+            current => {
+                optional => 1,
+		default => 0,
+                type => 'boolean',
+                description => "Get current values instead pending values",
+            },
 	},
     },
     returns => {
@@ -650,6 +656,17 @@ __PACKAGE__->register_method({
 	my $conf = PVE::QemuServer::load_config($param->{vmid});
 
 	delete $conf->{snapshots};
+
+	if(!$param->{current} || (defined($param->{current}) && $param->{current} == 0)) {
+	    foreach my $opt (keys $conf->{pending}) {
+		foreach my $opt (PVE::Tools::split_list($conf->{pending}->{delete})) {
+		    delete $conf->{$opt} if $conf->{$opt};
+		}
+		next if ref($conf->{pending}->{$opt}); # just to be sure
+		$conf->{$opt} = $conf->{pending}->{$opt};
+	    }
+	}
+
 	delete $conf->{pending};
 
 	return $conf;
@@ -685,11 +702,6 @@ __PACKAGE__->register_method({
 		    type => 'string',
 		    optional => 1,
 		},
-		pending => {
-		    description => "Pending value.",
-		    type => 'string',
-		    optional => 1,
-		},
 		delete => {
 		    description => "Indicated a pending delete request.",
 		    type => 'boolean',
@@ -1156,6 +1168,10 @@ __PACKAGE__->register_method({
 		    maxLength => 40,
 		    optional => 1,
 		},
+		pending => {
+		    optional => 1,
+		    type => 'boolean',
+		}
 	    }),
     },
     returns => { type => 'null' },
@@ -1166,7 +1182,6 @@ __PACKAGE__->register_method({
     }
 });
 
-
 __PACKAGE__->register_method({
     name => 'destroy_vm',
     path => '{vmid}',
-- 
1.7.10.4




More information about the pve-devel mailing list