On September 5, 2019 4:11 pm, Oguz Bektas wrote:
> analog to Qemu, it returns an array of elements, which shows the
> current value, pending value, and delete requests.

and again, this is completely identical to the Qemu API path (modulo 
comments, one superfluous next statement) except for the cipassword 
handling.

we could just move this into AbstractConfig, and let Qemu cleanup the 
cipassword after calling the shared code.

> 
> Signed-off-by: Oguz Bektas <o.bek...@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 9ddaf58..b885e90 100644
> --- a/src/PVE/API2/LXC.pm
> +++ b/src/PVE/API2/LXC.pm
> @@ -513,6 +513,7 @@ __PACKAGE__->register_method({
>  
>       my $res = [
>           { subdir => 'config' },
> +         { subdir => 'pending' },
>           { subdir => 'status' },
>           { subdir => 'vncproxy' },
>           { subdir => 'termproxy' },
> @@ -1863,4 +1864,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. " .
> +                 "The value 2 indicates a force-delete request.",
> +                 type => 'integer',
> +                 minimum => 0,
> +                 maximum => 2,
> +                 optional => 1,
> +             },
> +         },
> +     },
> +    },
> +    code => sub {
> +     my ($param) = @_;
> +
> +     my $conf = PVE::LXC::Config->load_config($param->{vmid});
> +
> +     my $pending_delete_hash = 
> PVE::LXC::Config->split_flagged_list($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;
> +     }
> +
> +     while (my ($opt, $force) = each %$pending_delete_hash) {
> +         next if $conf->{pending}->{$opt};
> +         next if $conf->{$opt};
> +         my $item = { key => $opt, delete => ($force ? 2 : 1)};
> +         push @$res, $item;
> +     }
> +
> +     return $res;
> +
> +    }});
> +
>  1;
> -- 
> 2.20.1
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to