]> git.proxmox.com Git - qemu-server.git/blob - PVE/API2/Qemu/Agent.pm
move guest agent api call to its own file
[qemu-server.git] / PVE / API2 / Qemu / Agent.pm
1 package PVE::API2::Qemu::Agent;
2
3 use strict;
4 use warnings;
5
6 use PVE::RESTHandler;
7 use PVE::JSONSchema qw(get_standard_option);
8 use PVE::QemuServer;
9
10 use base qw(PVE::RESTHandler);
11
12 my $guest_agent_commands = [
13 'ping',
14 'get-time',
15 'info',
16 'fsfreeze-status',
17 'fsfreeze-freeze',
18 'fsfreeze-thaw',
19 'fstrim',
20 'network-get-interfaces',
21 'get-vcpus',
22 'get-fsinfo',
23 'get-memory-blocks',
24 'get-memory-block-info',
25 'suspend-hybrid',
26 'suspend-ram',
27 'suspend-disk',
28 'shutdown',
29 ];
30
31 __PACKAGE__->register_method({
32 name => 'agent',
33 path => '',
34 method => 'POST',
35 protected => 1,
36 proxyto => 'node',
37 description => "Execute Qemu Guest Agent commands.",
38 permissions => {
39 check => ['perm', '/vms/{vmid}', [ 'VM.Monitor' ]],
40 },
41 parameters => {
42 additionalProperties => 0,
43 properties => {
44 node => get_standard_option('pve-node'),
45 vmid => get_standard_option('pve-vmid', {
46 completion => \&PVE::QemuServer::complete_vmid_running }),
47 command => {
48 type => 'string',
49 description => "The QGA command.",
50 enum => $guest_agent_commands,
51 },
52 },
53 },
54 returns => {
55 type => 'object',
56 description => "Returns an object with a single `result` property. The type of that
57 property depends on the executed command.",
58 },
59 code => sub {
60 my ($param) = @_;
61
62 my $vmid = $param->{vmid};
63
64 my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists
65
66 die "No Qemu Guest Agent\n" if !defined($conf->{agent});
67 die "VM $vmid is not running\n" if !PVE::QemuServer::check_running($vmid);
68
69 my $cmd = $param->{command};
70
71 my $res = PVE::QemuServer::vm_mon_cmd($vmid, "guest-$cmd");
72
73 return { result => $res };
74 }});
75
76 1;