]>
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 | |
c9138c03 | 9 | use base qw(PVE::APIClient::CLIHandler); |
5b090843 RJ |
10 | |
11 | __PACKAGE__->register_method ({ | |
12 | name => 'list', | |
13 | path => 'list', | |
14 | method => 'GET', | |
15 | description => "List containers.", | |
16 | parameters => { | |
17 | additionalProperties => 0, | |
18 | properties => { | |
19 | remote => get_standard_option('pveclient-remote-name'), | |
20 | format => { | |
21 | type => 'string', | |
22 | description => 'Output format', | |
23 | enum => [ 'table', 'json' ], | |
24 | optional => 1, | |
25 | default => 'table', | |
26 | } | |
27 | }, | |
28 | }, | |
29 | returns => { type => 'null'}, | |
30 | code => sub { | |
31 | my ($param) = @_; | |
32 | ||
33 | my $config = PVE::APIClient::Config->load(); | |
34 | my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote}); | |
35 | my $resources = $conn->get('api2/json/cluster/resources', { type => 'vm' }); | |
36 | ||
37 | if (!defined($param->{format}) or $param->{format} eq 'table') { | |
38 | my $headers = ['Node', 'VMID', 'Type', 'Name', 'Status']; | |
39 | my $data = []; | |
40 | for my $el (@$resources) { | |
41 | push(@$data, [$el->{node}, $el->{vmid}, $el->{type}, $el->{name}, $el->{status}]); | |
42 | } | |
43 | ||
44 | printf("%10s %10s %10s %10s %10s\n", @$headers); | |
45 | for my $row (@$data) { | |
46 | printf("%10s %10s %10s %10s %10s\n", @$row); | |
47 | } | |
48 | } else { | |
49 | print JSON::to_json($resources, {utf8 => 1, pretty => 1}); | |
50 | } | |
51 | ||
52 | return undef; | |
53 | }}); | |
54 | ||
55 | ||
56 | our $cmddef = [ __PACKAGE__, 'list', ['remote']]; | |
57 | ||
58 | 1; |