[pve-devel] [PATCH v4 14/14] implement API/CLI to get pending changes
Dietmar Maurer
dietmar at proxmox.com
Fri Nov 21 11:46:26 CET 2014
Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
PVE/API2/Qemu.pm | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
qm | 27 +++++++++++++++++
2 files changed, 112 insertions(+), 1 deletion(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index f3f0cf2..295d035 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 virtual machine configuration.",
+ description => "Get current virtual machine configuration. This does not include pending configuration changes (see 'pending' API).",
permissions => {
check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]],
},
@@ -650,10 +650,94 @@ __PACKAGE__->register_method({
my $conf = PVE::QemuServer::load_config($param->{vmid});
delete $conf->{snapshots};
+ delete $conf->{pending};
return $conf;
}});
+__PACKAGE__->register_method({
+ name => 'vm_pending',
+ path => '{vmid}/pending',
+ method => 'GET',
+ proxyto => 'node',
+ description => "Get virtual machine 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'),
+ },
+ },
+ 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 => "Indicated a pending delete request.",
+ type => 'boolean',
+ optional => 1,
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $conf = PVE::QemuServer::load_config($param->{vmid});
+
+ my $pending_delete_hash = {};
+ foreach my $opt (PVE::Tools::split_list($conf->{pending}->{delete})) {
+ $pending_delete_hash->{$opt} = 1;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ return $res;
+ }});
+
my $delete_drive = sub {
my ($conf, $storecfg, $vmid, $key, $drive, $force) = @_;
diff --git a/qm b/qm
index cea223e..d73b0ea 100755
--- a/qm
+++ b/qm
@@ -437,6 +437,33 @@ my $cmddef = {
}
}],
+ pending => [ "PVE::API2::Qemu", 'vm_pending', ['vmid'],
+ { node => $nodename }, sub {
+ my $data = shift;
+ foreach my $item (sort { $a->{key} cmp $b->{key}} @$data) {
+ my $k = $item->{key};
+ next if $k eq 'digest';
+ my $v = $item->{value};
+ my $p = $item->{pending};
+ if ($k eq 'description') {
+ $v = PVE::Tools::encode_text($v) if defined($v);
+ $p = PVE::Tools::encode_text($p) if defined($p);
+ }
+ if (defined($v)) {
+ if ($item->{delete}) {
+ print "del $k: $v\n";
+ } elsif (defined($p)) {
+ print "cur $k: $v\n";
+ print "new $k: $p\n";
+ } else {
+ print "cur $k: $v\n";
+ }
+ } elsif (defined($p)) {
+ print "new $k: $p\n";
+ }
+ }
+ }],
+
showcmd => [ __PACKAGE__, 'showcmd', ['vmid']],
status => [ __PACKAGE__, 'status', ['vmid']],
--
1.7.10.4
More information about the pve-devel
mailing list