]> git.proxmox.com Git - pve-client.git/blob - PVE/APIClient/Commands/list.pm
fix copyright date
[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 VMs and Containers.",
29 parameters => {
30 additionalProperties => 0,
31 properties => {
32 remote => get_standard_option('pveclient-remote-name'),
33 },
34 },
35 returns => {
36 type => 'array',
37 items => {
38 type => 'object',
39 properties => { @$list_returns_properties },
40 },
41 },
42 code => sub {
43 my ($param) = @_;
44
45 my $config = PVE::APIClient::Config->load();
46 my $conn = PVE::APIClient::Config->remote_conn($config, $param->{remote});
47
48 return $conn->get('api2/json/cluster/resources', { type => 'vm' });
49 }});
50
51
52 our $cmddef = [ __PACKAGE__, 'list', ['remote'], {},
53 sub {
54 my ($data, $schema, $options) = @_;
55 PVE::APIClient::Helpers::print_ordered_result($list_returns_properties, $data, $schema, $options);
56 },
57 $PVE::APIClient::RESTHandler::standard_output_options,
58 ];
59
60 1;