use warnings;
use PVE::APIClient::Commands::help;
+use PVE::APIClient::Commands::list;
use PVE::APIClient::Commands::lxc;
use PVE::APIClient::Commands::remote;
};
$assemble_usage_string->('help', $PVE::APIClient::Commands::help::cmddef);
+ $assemble_usage_string->('list', $PVE::APIClient::Commands::list::cmddef);
$assemble_usage_string->('lxc', $PVE::APIClient::Commands::lxc::cmddef);
$assemble_usage_string->('remote', $PVE::APIClient::Commands::remote::cmddef);
--- /dev/null
+package PVE::APIClient::Commands::list;
+
+use strict;
+use warnings;
+use JSON;
+
+use PVE::JSONSchema qw(get_standard_option);
+
+use base qw(PVE::CLIHandler);
+
+__PACKAGE__->register_method ({
+ name => 'list',
+ path => 'list',
+ method => 'GET',
+ description => "List containers.",
+ parameters => {
+ 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) = @_;
+
+ 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' });
+
+ if (!defined($param->{format}) or $param->{format} eq 'table') {
+ my $headers = ['Node', 'VMID', 'Type', 'Name', 'Status'];
+ my $data = [];
+ for my $el (@$resources) {
+ push(@$data, [$el->{node}, $el->{vmid}, $el->{type}, $el->{name}, $el->{status}]);
+ }
+
+ printf("%10s %10s %10s %10s %10s\n", @$headers);
+ for my $row (@$data) {
+ printf("%10s %10s %10s %10s %10s\n", @$row);
+ }
+ } else {
+ print JSON::to_json($resources, {utf8 => 1, pretty => 1});
+ }
+
+ return undef;
+ }});
+
+
+our $cmddef = [ __PACKAGE__, 'list', ['remote']];
+
+1;
\ No newline at end of file
return undef;
}});
-__PACKAGE__->register_method ({
- name => 'list',
- path => 'list',
- method => 'GET',
- description => "List containers.",
- parameters => {
- additionalProperties => 0,
- properties => {
- remote => get_standard_option('pveclient-remote-name'),
- },
- },
- returns => { type => 'null'},
- code => sub {
- my ($param) = @_;
-
- die "implement me";
-
- }});
-
-
our $cmddef = {
enter => [ __PACKAGE__, 'enter', ['remote', 'vmid']],
- list => [ __PACKAGE__, 'list', ['remote']],
};
1;
use PVE::APIClient::LWP;
use PVE::APIClient::Helpers;
use PVE::APIClient::Commands::remote;
+use PVE::APIClient::Commands::list;
use PVE::APIClient::Commands::lxc;
use PVE::APIClient::Commands::help;
}
my $cli_class_handlers = {
+ list => 'PVE::APIClient::Commands::list',
lxc => 'PVE::APIClient::Commands::lxc',
remote => 'PVE::APIClient::Commands::remote',
help => 'PVE::APIClient::Commands::help',