-my $guest_agent_commands = [
- 'guest-ping',
- 'guest-get-time',
- 'guest-info',
- 'guest-fsfreeze-status',
- 'guest-fsfreeze-freeze',
- 'guest-fsfreeze-thaw',
- 'guest-fstrim',
- 'guest-network-get-interfaces',
- 'guest-get-vcpus',
- 'guest-get-fsinfo',
- 'guest-get-memory-blocks',
- 'guest-get-memory-block-info',
- 'guest-suspend-hybrid',
- 'guest-suspend-ram',
- 'guest-suspend-disk',
- 'guest-shutdown',
- ];
-
-__PACKAGE__->register_method({
- name => 'agent',
- path => '{vmid}/agent',
- method => 'POST',
- protected => 1,
- proxyto => 'node',
- description => "Execute Qemu Guest Agent commands.",
- permissions => {
- check => ['perm', '/vms/{vmid}', [ 'VM.Monitor' ]],
- },
- parameters => {
- additionalProperties => 0,
- properties => {
- node => get_standard_option('pve-node'),
- vmid => get_standard_option('pve-vmid', {
- completion => \&PVE::QemuServer::complete_vmid_running }),
- command => {
- type => 'string',
- description => "The QGA command.",
- enum => $guest_agent_commands,
- },
- },
- },
- returns => { type => 'object' },
- code => sub {
- my ($param) = @_;
-
- my $vmid = $param->{vmid};
-
- my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists
-
- die "Only qga commands are allowed\n" if $param->{command} !~ m/^guest-.*$/;
- die "No Qemu Guest Agent\n" if !defined($conf->{agent});
- die "VM $vmid is not running\n" if !PVE::QemuServer::check_running($vmid);
-
- my $res = '';
- eval {
- $res = PVE::QemuServer::vm_mon_cmd($vmid, $param->{command});
- };
-
- if (my $err = $@) {
- return {'ERROR:', $err};
- } else {
- return {'OK:', $res};
- }
- }});
-