]> git.proxmox.com Git - pve-container.git/commitdiff
api: config: use shared guesthelpers in GET call
authorOguz Bektas <o.bektas@proxmox.com>
Mon, 14 Oct 2019 08:28:44 +0000 (10:28 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Oct 2019 18:44:36 +0000 (20:44 +0200)
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@proxmox.com>
src/PVE/API2/LXC/Config.pm

index 769fc3bfc14ae784b1d3cd283ee41225fc4da911..41e75a8757d9362366768e67aa22df9acc12e6fe 100644 (file)
@@ -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;
     }});