[pve-devel] [PATCH pve-client] Add 'lxc list'

Dietmar Maurer dietmar at proxmox.com
Mon Jun 11 10:21:46 CEST 2018


comments inline

> On June 8, 2018 at 9:44 AM René Jochum <r.jochum at proxmox.com> wrote:
> 
> 
> ---
>  PVE/APIClient/Commands/lxc.pm | 82
> ++++++++++++++++++++++++++++++++++++++++++-
>  PVE/APIClient/Helpers.pm      | 14 ++++++++
>  2 files changed, 95 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/APIClient/Commands/lxc.pm b/PVE/APIClient/Commands/lxc.pm
> index f0c85f7..0f6f638 100644
> --- a/PVE/APIClient/Commands/lxc.pm
> +++ b/PVE/APIClient/Commands/lxc.pm
> @@ -18,6 +18,7 @@ use PVE::PTY;
>  
>  use base qw(PVE::CLIHandler);
>  use PVE::APIClient::Config;
> +use PVE::APIClient::Helpers;
>  
>  my $CRLF = "\x0D\x0A";
>  my $max_payload_size = 128*1024;
> @@ -356,14 +357,93 @@ __PACKAGE__->register_method ({
>  	additionalProperties => 0,
>  	properties => {
>  	    remote => get_standard_option('pveclient-remote-name'),
> +	    format => {
> +		type => 'string',
> +		description => 'Output format',
> +		enum => [ 'table', 'json' ],
> +		optional => 1,
> +		default => 'table',
> +	    }
>  	},
>      },
>      returns => { type => 'null'},
>      code => sub {
>  	my ($param) = @_;
>  
> -	die "implement me";
> +	my $config = PVE::APIClient::Config->load();
> +	my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote});
> +	my $resources = $conn->get('api2/json/cluster/resources', { type => 'vm' });
> +	my $lxcs = [grep({$_->{type} eq "lxc"} @$resources)];
> +
> +	my $glxcs = [];
> +	for my $el (@$lxcs) {
> +	    my $node = $el->{node};
> +	    my $vmid = $el->{vmid};
> +
> +	    my $lxc_config = $conn->get("api2/json/nodes/$node/lxc/$vmid/config",
> {});

This is probably a bad idea, because you generate one additional API call for
each guest.
On large clusters, this generate and really high number of calls.

The whole purpose of /cluster/resources is to avoid this.



More information about the pve-devel mailing list