]>
Commit | Line | Data |
---|---|---|
5b090843 RJ |
1 | package PVE::APIClient::Commands::list; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use JSON; | |
6 | ||
c9138c03 | 7 | use PVE::APIClient::JSONSchema qw(get_standard_option); |
5b090843 | 8 | |
ef03892d DM |
9 | use PVE::APIClient::Config; |
10 | use PVE::APIClient::CLIHandler; | |
11 | ||
c9138c03 | 12 | use base qw(PVE::APIClient::CLIHandler); |
5b090843 RJ |
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'), | |
cbfba90b | 23 | format => get_standard_option('pveclient-output-format'), |
5b090843 RJ |
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 | ||
b5aeedb0 | 34 | if (!defined($param->{format}) or $param->{format} eq 'text') { |
5b090843 RJ |
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 | ||
ef03892d | 55 | 1; |