[pve-devel] [PATCH v2 container 08/18] add lxc/pending API path

Oguz Bektas o.bektas at proxmox.com
Mon Sep 30 14:44:40 CEST 2019


Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
---
 src/PVE/API2/LXC.pm | 88 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 07280fb..9c040d1 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -515,6 +515,7 @@ __PACKAGE__->register_method({
 
 	my $res = [
 	    { subdir => 'config' },
+	    { subdir => 'pending' },
 	    { subdir => 'status' },
 	    { subdir => 'vncproxy' },
 	    { subdir => 'termproxy' },
@@ -1865,4 +1866,91 @@ __PACKAGE__->register_method({
 	return $task;
   }});
 
+__PACKAGE__->register_method({
+    name => 'vm_pending',
+    path => '{vmid}/pending',
+    method => 'GET',
+    proxyto => 'node',
+    description => 'Get container configuration, including pending changes.',
+    permissions => {
+	check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
+	},
+    },
+    returns => {
+	type => "array",
+	items => {
+	    type => "object",
+	    properties => {
+		key => {
+		    description => 'Configuration option name.',
+		    type => 'string',
+		},
+		value => {
+		    description => 'Current value.',
+		    type => 'string',
+		    optional => 1,
+		},
+		pending => {
+		    description => 'Pending value.',
+		    type => 'string',
+		    optional => 1,
+		},
+		delete => {
+		    description => "Indicates a pending delete request if present and not 0.",
+		    type => 'integer',
+		    minimum => 0,
+		    maximum => 1,
+		    optional => 1,
+		},
+	    },
+	},
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my $conf = PVE::LXC::Config->load_config($param->{vmid});
+
+	my $pending_delete_hash = PVE::LXC::Config->parse_pending_delete($conf->{pending}->{delete});
+
+	my $res = [];
+
+	foreach my $opt (keys %$conf) {
+	    next if ref($conf->{$opt});
+	    next if $opt eq 'pending';
+	    my $item = { key => $opt } ;
+	    $item->{value} = $conf->{$opt} if defined($conf->{$opt});
+	    $item->{pending} = $conf->{pending}->{$opt} if defined($conf->{pending}->{$opt});
+	    $item->{delete} = ($pending_delete_hash->{$opt} ? 2 : 1) if exists $pending_delete_hash->{$opt};
+
+	    push @$res, $item;
+	}
+
+	foreach my $opt (keys %{$conf->{pending}}) {
+	    next if $opt eq 'delete';
+	    next if ref($conf->{pending}->{$opt});
+	    next if defined($conf->{$opt});
+	    my $item = { key => $opt };
+	    $item->{pending} = $conf->{pending}->{$opt};
+
+	    push @$res, $item;
+	}
+
+	# FIXME: $force delete is not implemented for CTs
+	while (my ($opt, undef) = each %$pending_delete_hash) {
+	    next if $conf->{pending}->{$opt};
+	    next if $conf->{$opt};
+	    my $item = { key => $opt, delete => 1 };
+	    push @$res, $item;
+	}
+
+	return $res;
+
+    }});
+
 1;
-- 
2.20.1




More information about the pve-devel mailing list