]> git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/list.pm
make timeouts optional
[pve-client.git] / PVE / APIClient / Commands / list.pm
1 package PVE::APIClient::Commands::list;
2
3 use strict;
4 use warnings;
5 use JSON;
6
7 use PVE::APIClient::JSONSchema qw(get_standard_option);
8
9 use PVE::APIClient::Config;
10 use PVE::APIClient::CLIHandler;
11
12 use base qw(PVE::APIClient::CLIHandler);
13
14 __PACKAGE__->register_method ({
15 name => 'list',
16 path => 'list',
17 method => 'GET',
18 description => "List containers.",
19 parameters => {
20 additionalProperties => 0,
21 properties => {
22 remote => get_standard_option('pveclient-remote-name'),
23 format => get_standard_option('pveclient-output-format'),
24 },
25 },
26 returns => { type => 'null'},
27 code => sub {
28 my ($param) = @_;
29
30 my $config = PVE::APIClient::Config->load();
31 my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote});
32 my $resources = $conn->get('api2/json/cluster/resources', { type => 'vm' });
33
34 if (!defined($param->{format}) or $param->{format} eq 'text') {
35 my $headers = ['Node', 'VMID', 'Type', 'Name', 'Status'];
36 my $data = [];
37 for my $el (@$resources) {
38 push(@$data, [$el->{node}, $el->{vmid}, $el->{type}, $el->{name}, $el->{status}]);
39 }
40
41 printf("%10s %10s %10s %10s %10s\n", @$headers);
42 for my $row (@$data) {
43 printf("%10s %10s %10s %10s %10s\n", @$row);
44 }
45 } else {
46 print JSON::to_json($resources, {utf8 => 1, pretty => 1});
47 }
48
49 return undef;
50 }});
51
52
53 our $cmddef = [ __PACKAGE__, 'list', ['remote']];
54
55 1;