]> git.proxmox.com Git - pve-client.git/blame - PVE/APIClient/Commands/list.pm
register stanadard option 'pveclient-output-format'
[pve-client.git] / PVE / APIClient / Commands / list.pm
CommitLineData
5b090843
RJ
1package PVE::APIClient::Commands::list;
2
3use strict;
4use warnings;
5use JSON;
6
c9138c03 7use PVE::APIClient::JSONSchema qw(get_standard_option);
5b090843 8
ef03892d
DM
9use PVE::APIClient::Config;
10use PVE::APIClient::CLIHandler;
11
c9138c03 12use 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
34 if (!defined($param->{format}) or $param->{format} eq 'table') {
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
53our $cmddef = [ __PACKAGE__, 'list', ['remote']];
54
ef03892d 551;