]>
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'), | |
23 | format => { | |
24 | type => 'string', | |
25 | description => 'Output format', | |
26 | enum => [ 'table', 'json' ], | |
27 | optional => 1, | |
28 | default => 'table', | |
29 | } | |
30 | }, | |
31 | }, | |
32 | returns => { type => 'null'}, | |
33 | code => sub { | |
34 | my ($param) = @_; | |
35 | ||
36 | my $config = PVE::APIClient::Config->load(); | |
37 | my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote}); | |
38 | my $resources = $conn->get('api2/json/cluster/resources', { type => 'vm' }); | |
39 | ||
40 | if (!defined($param->{format}) or $param->{format} eq 'table') { | |
41 | my $headers = ['Node', 'VMID', 'Type', 'Name', 'Status']; | |
42 | my $data = []; | |
43 | for my $el (@$resources) { | |
44 | push(@$data, [$el->{node}, $el->{vmid}, $el->{type}, $el->{name}, $el->{status}]); | |
45 | } | |
46 | ||
47 | printf("%10s %10s %10s %10s %10s\n", @$headers); | |
48 | for my $row (@$data) { | |
49 | printf("%10s %10s %10s %10s %10s\n", @$row); | |
50 | } | |
51 | } else { | |
52 | print JSON::to_json($resources, {utf8 => 1, pretty => 1}); | |
53 | } | |
54 | ||
55 | return undef; | |
56 | }}); | |
57 | ||
58 | ||
59 | our $cmddef = [ __PACKAGE__, 'list', ['remote']]; | |
60 | ||
ef03892d | 61 | 1; |