[pve-devel] [PATCH] add configpending api

Alexandre Derumier aderumier at odiso.com
Fri Dec 19 11:55:31 CET 2014


get the current config with pending applied

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

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index fb36ce8..20c0438 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -656,6 +656,50 @@ __PACKAGE__->register_method({
     }});
 
 __PACKAGE__->register_method({
+    name => 'vm_configpending',
+    path => '{vmid}/configpending',
+    method => 'GET',
+    proxyto => 'node',
+    description => "Get current virtual machine configuration with pending changes applied.",
+    permissions => {
+	check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
+    },
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    vmid => get_standard_option('pve-vmid'),
+	},
+    },
+    returns => {
+	type => "object",
+	properties => {
+	    digest => {
+		type => 'string',
+		description => 'SHA1 digest of configuration file. This can be used to prevent concurrent modifications.',
+	    }
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $conf = PVE::QemuServer::load_config($param->{vmid});
+
+	delete $conf->{snapshots};
+
+        foreach my $opt (keys $conf->{pending}) {
+            next if $opt eq 'delete';
+            next if ref($conf->{pending}->{$opt}); # just to be sure
+	    $conf->{$opt} = $conf->{pending}->{$opt};
+        }
+
+
+	delete $conf->{pending};
+
+	return $conf;
+    }});
+
+__PACKAGE__->register_method({
     name => 'vm_pending',
     path => '{vmid}/pending',
     method => 'GET',
@@ -1166,6 +1210,50 @@ __PACKAGE__->register_method({
     }
 });
 
+__PACKAGE__->register_method({
+    name => 'update_vm_pending',
+    path => '{vmid}/configpending',
+    method => 'PUT',
+    protected => 1,
+    proxyto => 'node',
+    description => "Set virtual machine options (synchrounous API) - You should consider using the POST method instead for any actions involving hotplug or storage allocation.",
+    permissions => {
+	check => ['perm', '/vms/{vmid}', $vm_config_perm_list, any => 1],
+    },
+    parameters => {
+    	additionalProperties => 0,
+	properties => PVE::QemuServer::json_config_properties(
+	    {
+		node => get_standard_option('pve-node'),
+		vmid => get_standard_option('pve-vmid'),
+		skiplock => get_standard_option('skiplock'),
+		delete => {
+		    type => 'string', format => 'pve-configid-list',
+		    description => "A list of settings you want to delete.",
+		    optional => 1,
+		},
+		force => {
+		    type => 'boolean',
+		    description => $opt_force_description,
+		    optional => 1,
+		    requires => 'delete',
+		},
+		digest => {
+		    type => 'string',
+		    description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
+		    maxLength => 40,
+		    optional => 1,
+		},
+	    }),
+    },
+    returns => { type => 'null' },
+    code => sub {
+	my ($param) = @_;
+	&$update_vm_api($param, 1);
+	return undef;
+    }
+});
+
 
 __PACKAGE__->register_method({
     name => 'destroy_vm',
-- 
1.7.10.4




More information about the pve-devel mailing list