]>
git.proxmox.com Git - qemu-server.git/blob - PVE/API2/Qemu/Agent.pm
1 package PVE
::API2
::Qemu
::Agent
;
7 use PVE
::JSONSchema
qw(get_standard_option);
9 use PVE
::QemuServer
::Agent
qw(agent_available);
11 use base
qw(PVE::RESTHandler);
14 # will generate one api endpoint per command
15 # needs a 'method' property and optionally a 'perms' property (default VM.Monitor)
16 my $guest_agent_commands = {
26 'fsfreeze-status' => {
29 'fsfreeze-freeze' => {
38 'network-get-interfaces' => {
47 'get-memory-blocks' => {
50 'get-memory-block-info' => {
65 # added since qemu 2.9
80 __PACKAGE__-
>register_method({
85 description
=> "Qemu Agent command index.",
90 additionalProperties
=> 1,
92 node
=> get_standard_option
('pve-node'),
93 vmid
=> get_standard_option
('pve-vmid', {
94 completion
=> \
&PVE
::QemuServer
::complete_vmid_running
}),
103 links
=> [ { rel
=> 'child', href
=> '{name}' } ],
104 description
=> "Returns the list of Qemu Agent commands",
111 for my $cmd (sort keys %$guest_agent_commands) {
112 push @$result, { name
=> $cmd };
118 sub register_command
{
119 my ($class, $command, $method, $perm) = @_;
121 die "no method given\n" if !$method;
122 die "no command given\n" if !defined($command);
126 if (ref($perm) eq 'HASH') {
129 $perm //= 'VM.Monitor';
130 $permission = { check
=> [ 'perm', '/vms/{vmid}', [ $perm ]]};
134 additionalProperties
=> 0,
136 node
=> get_standard_option
('pve-node'),
137 vmid
=> get_standard_option
('pve-vmid', {
138 completion
=> \
&PVE
::QemuServer
::complete_vmid_running
}),
141 description
=> "The QGA command.",
142 enum
=> [ sort keys %$guest_agent_commands ],
147 my $description = "Execute Qemu Guest Agent commands.";
150 if ($command ne '') {
151 $description = "Execute $command.";
153 delete $parameters->{properties
}->{command
};
156 __PACKAGE__-
>register_method({
162 description
=> $description,
163 permissions
=> $permission,
164 parameters
=> $parameters,
167 description
=> "Returns an object with a single `result` property.",
172 my $vmid = $param->{vmid
};
174 my $conf = PVE
::QemuConfig-
>load_config ($vmid); # check if VM exists
176 agent_available
($vmid, $conf);
178 my $cmd = $param->{command
} // $command;
179 my $res = PVE
::QemuServer
::vm_mon_cmd
($vmid, "guest-$cmd");
181 return { result
=> $res };
185 # old {vmid}/agent POST endpoint, here for compatibility
186 __PACKAGE__-
>register_command('', 'POST');
188 for my $cmd (sort keys %$guest_agent_commands) {
189 my $props = $guest_agent_commands->{$cmd};
190 __PACKAGE__-
>register_command($cmd, $props->{method}, $props->{perms
});