]>
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 | |
5101e472 | 9 | use PVE::APIClient::Helpers; |
ef03892d DM |
10 | use PVE::APIClient::Config; |
11 | use PVE::APIClient::CLIHandler; | |
12 | ||
c9138c03 | 13 | use base qw(PVE::APIClient::CLIHandler); |
5b090843 | 14 | |
5101e472 DM |
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 | ||
5b090843 RJ |
24 | __PACKAGE__->register_method ({ |
25 | name => 'list', | |
26 | path => 'list', | |
27 | method => 'GET', | |
4aba8d31 | 28 | description => "List VMs and Containers.", |
5b090843 RJ |
29 | parameters => { |
30 | additionalProperties => 0, | |
31 | properties => { | |
32 | remote => get_standard_option('pveclient-remote-name'), | |
5101e472 DM |
33 | }, |
34 | }, | |
35 | returns => { | |
36 | type => 'array', | |
37 | items => { | |
38 | type => 'object', | |
39 | properties => { @$list_returns_properties }, | |
5b090843 RJ |
40 | }, |
41 | }, | |
5b090843 RJ |
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}); | |
5101e472 DM |
47 | |
48 | return $conn->get('api2/json/cluster/resources', { type => 'vm' }); | |
5b090843 RJ |
49 | }}); |
50 | ||
51 | ||
4aba8d31 DM |
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 | ]; | |
5b090843 | 59 | |
ef03892d | 60 | 1; |