]>
git.proxmox.com Git - qemu-server.git/blob - PVE/API2/Qemu/Agent.pm
b046d2d66dc567ee0e24bf4392e5fa3dda9c42c8
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' => {
66 __PACKAGE__-
>register_method({
71 description
=> "Qemu Agent command index.",
76 additionalProperties
=> 1,
78 node
=> get_standard_option
('pve-node'),
79 vmid
=> get_standard_option
('pve-vmid', {
80 completion
=> \
&PVE
::QemuServer
::complete_vmid_running
}),
89 links
=> [ { rel
=> 'child', href
=> '{name}' } ],
90 description
=> "Returns the list of Qemu Agent commands",
97 for my $cmd (sort keys %$guest_agent_commands) {
98 push @$result, { name
=> $cmd };
104 sub register_command
{
105 my ($class, $command, $method, $perm) = @_;
107 die "no method given\n" if !$method;
108 die "no command given\n" if !defined($command);
112 if (ref($perm) eq 'HASH') {
115 $perm //= 'VM.Monitor';
116 $permission = { check
=> [ 'perm', '/vms/{vmid}', [ $perm ]]};
120 additionalProperties
=> 0,
122 node
=> get_standard_option
('pve-node'),
123 vmid
=> get_standard_option
('pve-vmid', {
124 completion
=> \
&PVE
::QemuServer
::complete_vmid_running
}),
127 description
=> "The QGA command.",
128 enum
=> [ sort keys %$guest_agent_commands ],
133 my $description = "Execute Qemu Guest Agent commands.";
136 if ($command ne '') {
137 $description = "Execute $command.";
139 delete $parameters->{properties
}->{command
};
142 __PACKAGE__-
>register_method({
148 description
=> $description,
149 permissions
=> $permission,
150 parameters
=> $parameters,
153 description
=> "Returns an object with a single `result` property.",
158 my $vmid = $param->{vmid
};
160 my $conf = PVE
::QemuConfig-
>load_config ($vmid); # check if VM exists
162 die "No Qemu Guest Agent\n" if !defined($conf->{agent
});
163 die "VM $vmid is not running\n" if !PVE
::QemuServer
::check_running
($vmid);
165 my $cmd = $param->{command
} // $command;
166 my $res = PVE
::QemuServer
::vm_mon_cmd
($vmid, "guest-$cmd");
168 return { result
=> $res };
172 # old {vmid}/agent POST endpoint, here for compatibility
173 __PACKAGE__-
>register_command('', 'POST');
175 for my $cmd (sort keys %$guest_agent_commands) {
176 my $props = $guest_agent_commands->{$cmd};
177 __PACKAGE__-
>register_command($cmd, $props->{method}, $props->{perms
});