]>
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);
10 use base
qw(PVE::RESTHandler);
13 # will generate one api endpoint per command
14 # needs a 'method' property and optionally a 'perms' property (default VM.Monitor)
15 my $guest_agent_commands = {
25 'fsfreeze-status' => {
28 'fsfreeze-freeze' => {
37 'network-get-interfaces' => {
46 'get-memory-blocks' => {
49 'get-memory-block-info' => {
64 # added since qemu 2.9
79 __PACKAGE__-
>register_method({
84 description
=> "Qemu Agent command index.",
89 additionalProperties
=> 1,
91 node
=> get_standard_option
('pve-node'),
92 vmid
=> get_standard_option
('pve-vmid', {
93 completion
=> \
&PVE
::QemuServer
::complete_vmid_running
}),
102 links
=> [ { rel
=> 'child', href
=> '{name}' } ],
103 description
=> "Returns the list of Qemu Agent commands",
110 for my $cmd (sort keys %$guest_agent_commands) {
111 push @$result, { name
=> $cmd };
117 sub register_command
{
118 my ($class, $command, $method, $perm) = @_;
120 die "no method given\n" if !$method;
121 die "no command given\n" if !defined($command);
125 if (ref($perm) eq 'HASH') {
128 $perm //= 'VM.Monitor';
129 $permission = { check
=> [ 'perm', '/vms/{vmid}', [ $perm ]]};
133 additionalProperties
=> 0,
135 node
=> get_standard_option
('pve-node'),
136 vmid
=> get_standard_option
('pve-vmid', {
137 completion
=> \
&PVE
::QemuServer
::complete_vmid_running
}),
140 description
=> "The QGA command.",
141 enum
=> [ sort keys %$guest_agent_commands ],
146 my $description = "Execute Qemu Guest Agent commands.";
149 if ($command ne '') {
150 $description = "Execute $command.";
152 delete $parameters->{properties
}->{command
};
155 __PACKAGE__-
>register_method({
161 description
=> $description,
162 permissions
=> $permission,
163 parameters
=> $parameters,
166 description
=> "Returns an object with a single `result` property.",
171 my $vmid = $param->{vmid
};
173 my $conf = PVE
::QemuConfig-
>load_config ($vmid); # check if VM exists
175 die "No Qemu Guest Agent\n" if !defined($conf->{agent
});
176 die "VM $vmid is not running\n" if !PVE
::QemuServer
::check_running
($vmid);
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
});