]>
Commit | Line | Data |
---|---|---|
89335fb1 DM |
1 | package PVE::APIClient::Commands::GuestStatus; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::APIClient::Helpers; | |
7 | use PVE::APIClient::Config; | |
8 | ||
9 | use PVE::JSONSchema qw(get_standard_option); | |
10 | ||
11 | use PVE::CLIHandler; | |
12 | ||
13 | use base qw(PVE::CLIHandler); | |
14 | ||
15 | my $guest_status_command = sub { | |
16 | my ($remote, $vmid, $cmd, $param) = @_, | |
17 | ||
18 | my $config = PVE::APIClient::Config->load(); | |
19 | my $conn = PVE::APIClient::Config->remote_conn($config, $remote); | |
20 | ||
21 | my $resource = PVE::APIClient::Helpers::get_vmid_resource($conn, $vmid); | |
22 | ||
23 | my $upid = $conn->post("api2/json/nodes/$resource->{node}/$resource->{type}/$resource->{vmid}/status/$cmd", $param); | |
24 | ||
25 | print PVE::APIClient::Helpers::poll_task($conn, $resource->{node}, $upid) . "\n"; | |
26 | }; | |
27 | ||
28 | __PACKAGE__->register_method ({ | |
29 | name => 'start', | |
30 | path => 'start', | |
31 | method => 'POST', | |
32 | description => "Start a guest (VM/Container).", | |
33 | parameters => { | |
34 | additionalProperties => 0, | |
35 | properties => { | |
36 | remote => get_standard_option('pveclient-remote-name'), | |
37 | vmid => get_standard_option('pve-vmid'), | |
38 | }, | |
39 | }, | |
40 | returns => { type => 'null'}, | |
41 | code => sub { | |
42 | my ($param) = @_; | |
43 | ||
44 | my $remote = PVE::Tools::extract_param($param, 'remote'); | |
45 | my $vmid = PVE::Tools::extract_param($param, 'vmid'); | |
46 | ||
47 | $guest_status_command->($remote, $vmid, 'start', $param); | |
48 | ||
49 | return undef; | |
50 | }}); | |
51 | ||
52 | __PACKAGE__->register_method ({ | |
53 | name => 'stop', | |
54 | path => 'stop', | |
55 | method => 'POST', | |
56 | description => "Stop a guest (VM/Container).", | |
57 | parameters => { | |
58 | additionalProperties => 0, | |
59 | properties => { | |
60 | remote => get_standard_option('pveclient-remote-name'), | |
61 | vmid => get_standard_option('pve-vmid'), | |
62 | }, | |
63 | }, | |
64 | returns => { type => 'null'}, | |
65 | code => sub { | |
66 | my ($param) = @_; | |
67 | ||
68 | my $remote = PVE::Tools::extract_param($param, 'remote'); | |
69 | my $vmid = PVE::Tools::extract_param($param, 'vmid'); | |
70 | ||
71 | $guest_status_command->($remote, $vmid, 'stop', $param); | |
72 | ||
73 | return undef; | |
74 | }}); | |
75 | ||
76 | 1; |