[pve-devel] [PATCH v3 container 12/19] api: config: use shared guesthelpers in GET call

Oguz Bektas o.bektas at proxmox.com
Mon Oct 14 10:28:44 CEST 2019


since containers can also have pending changes now, we need a method to
get the current applied config as well as the one with the pending
changes inside. this makes the GET config api more consistent with
qemu-server's by reusing load_current_config and load_snapshot_config from
AbstractConfig.
to decide which method to call, we look at the parameters.

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

diff --git a/src/PVE/API2/LXC/Config.pm b/src/PVE/API2/LXC/Config.pm
index 769fc3b..41e75a8 100644
--- a/src/PVE/API2/LXC/Config.pm
+++ b/src/PVE/API2/LXC/Config.pm
@@ -34,6 +34,12 @@ __PACKAGE__->register_method({
 	properties => {
 	    node => get_standard_option('pve-node'),
 	    vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
+	    current => {
+		description => "Get current values (instead of pending values).",
+		optional => 1,
+		default => 0,
+		type => 'boolean',
+	    },
 	    snapshot => get_standard_option('pve-snapshot-name', {
 		description => "Fetch config values from given snapshot.",
 		optional => 1,
@@ -62,19 +68,17 @@ __PACKAGE__->register_method({
     code => sub {
 	my ($param) = @_;
 
-	my $conf = PVE::LXC::Config->load_config($param->{vmid});
+	raise_param_exc({ snapshot => "cannot use 'snapshot' parameter with 'current'",
+	                  current => "cannot use 'snapshot' parameter with 'current'"})
+	    if ($param->{snapshot} && $param->{current});
 
-	if (my $snapname = $param->{snapshot}) {
-	    my $snapshot = $conf->{snapshots}->{$snapname};
-	    die "snapshot '$snapname' does not exist\n" if !defined($snapshot);
-
-	    # we need the digest of the file
-	    $snapshot->{digest} = $conf->{digest};
-	    $conf = $snapshot;
+	my $conf;
+	if ($param->{snapshot}) {
+	    $conf = PVE::LXC::Config->load_snapshot_config($param->{vmid}, $param->{snapshot});
+	} else {
+	    $conf = PVE::LXC::Config->load_current_config($param->{vmid}, $param->{current});
 	}
 
-	delete $conf->{snapshots};
-
 	return $conf;
     }});
 
-- 
2.20.1




More information about the pve-devel mailing list