]> git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/list.pm
adopt code for changes in pve-common
[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::Helpers;
10 use PVE::APIClient::Config;
11 use PVE::APIClient::CLIHandler;
12
13 use base qw(PVE::APIClient::CLIHandler);
14
15 # define as array to keep ordering
16 my $list_returns_properties = [
17 'vmid' => get_standard_option('pve-vmid'),
18 'node' => get_standard_option('pve-node'),
19 'type' => { type => 'string' },
20 'status' => { type => 'string' },
21 'name' => { type => 'string', optional => 1 },
22 ];
23
24 __PACKAGE__->register_method ({
25 name => 'list',
26 path => 'list',
27 method => 'GET',
28 description => "List containers.",
29 parameters => {
30 additionalProperties => 0,
31 properties => {
32 remote => get_standard_option('pveclient-remote-name'),
33 'format' => get_standard_option('pve-output-format'),
34 },
35 },
36 returns => {
37 type => 'array',
38 items => {
39 type => 'object',
40 properties => { @$list_returns_properties },
41 },
42 },
43 code => sub {
44 my ($param) = @_;
45
46 my $format = PVE::APIClient::Tools::extract_param($param, 'format');
47 PVE::APIClient::Helpers::set_output_format($format);
48
49 my $config = PVE::APIClient::Config->load();
50 my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote});
51
52 return $conn->get('api2/json/cluster/resources', { type => 'vm' });
53 }});
54
55
56 our $cmddef = [ __PACKAGE__, 'list', ['remote'], {}, sub {
57 PVE::APIClient::Helpers::print_ordered_result($list_returns_properties, @_);
58 }];
59
60 1;