5
0
mirror of git://git.proxmox.com/git/qemu-server.git synced 2025-03-12 20:58:26 +03:00

move guest agent api call to its own file

so we do not pollute the Qemu.pm too much

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2018-02-13 16:47:09 +01:00 committed by Thomas Lamprecht
parent c9a074b8bf
commit b8158701aa
5 changed files with 91 additions and 65 deletions

@ -2,3 +2,4 @@
install:
install -d -m 0755 ${DESTDIR}${PERLDIR}/PVE/API2
install -D -m 0644 Qemu.pm ${DESTDIR}${PERLDIR}/PVE/API2/Qemu.pm
make -C Qemu install

@ -26,6 +26,7 @@ use PVE::INotify;
use PVE::Network;
use PVE::Firewall;
use PVE::API2::Firewall::VM;
use PVE::API2::Qemu::Agent;
BEGIN {
if (!$ENV{PVE_GENERATING_DOCS}) {
@ -631,6 +632,11 @@ __PACKAGE__->register_method ({
path => '{vmid}/firewall',
});
__PACKAGE__->register_method ({
subclass => "PVE::API2::Qemu::Agent",
path => '{vmid}/agent',
});
__PACKAGE__->register_method({
name => 'rrd',
path => '{vmid}/rrd',
@ -3042,70 +3048,6 @@ __PACKAGE__->register_method({
return $res;
}});
my $guest_agent_commands = [
'ping',
'get-time',
'info',
'fsfreeze-status',
'fsfreeze-freeze',
'fsfreeze-thaw',
'fstrim',
'network-get-interfaces',
'get-vcpus',
'get-fsinfo',
'get-memory-blocks',
'get-memory-block-info',
'suspend-hybrid',
'suspend-ram',
'suspend-disk',
'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',
description => "Returns an object with a single `result` property. The type of that
property depends on the executed command.",
},
code => sub {
my ($param) = @_;
my $vmid = $param->{vmid};
my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists
die "No Qemu Guest Agent\n" if !defined($conf->{agent});
die "VM $vmid is not running\n" if !PVE::QemuServer::check_running($vmid);
my $cmd = $param->{command};
my $res = PVE::QemuServer::vm_mon_cmd($vmid, "guest-$cmd");
return { result => $res };
}});
__PACKAGE__->register_method({
name => 'resize_vm',
path => '{vmid}/resize',

76
PVE/API2/Qemu/Agent.pm Normal file

@ -0,0 +1,76 @@
package PVE::API2::Qemu::Agent;
use strict;
use warnings;
use PVE::RESTHandler;
use PVE::JSONSchema qw(get_standard_option);
use PVE::QemuServer;
use base qw(PVE::RESTHandler);
my $guest_agent_commands = [
'ping',
'get-time',
'info',
'fsfreeze-status',
'fsfreeze-freeze',
'fsfreeze-thaw',
'fstrim',
'network-get-interfaces',
'get-vcpus',
'get-fsinfo',
'get-memory-blocks',
'get-memory-block-info',
'suspend-hybrid',
'suspend-ram',
'suspend-disk',
'shutdown',
];
__PACKAGE__->register_method({
name => 'agent',
path => '',
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',
description => "Returns an object with a single `result` property. The type of that
property depends on the executed command.",
},
code => sub {
my ($param) = @_;
my $vmid = $param->{vmid};
my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM exists
die "No Qemu Guest Agent\n" if !defined($conf->{agent});
die "VM $vmid is not running\n" if !PVE::QemuServer::check_running($vmid);
my $cmd = $param->{command};
my $res = PVE::QemuServer::vm_mon_cmd($vmid, "guest-$cmd");
return { result => $res };
}});
1;

6
PVE/API2/Qemu/Makefile Normal file

@ -0,0 +1,6 @@
SOURCES=Agent.pm
.PHONY: install
install:
install -d -m 0755 ${DESTDIR}${PERLDIR}/PVE/API2/Qemu
for i in ${SOURCES}; do install -D -m 0644 $$i ${DESTDIR}${PERLDIR}/PVE/API2/Qemu/$$i; done

@ -20,6 +20,7 @@ use PVE::QemuServer;
use PVE::QemuServer::ImportDisk;
use PVE::QemuServer::OVF;
use PVE::API2::Qemu;
use PVE::API2::Qemu::Agent;
use JSON;
use PVE::JSONSchema qw(get_standard_option);
use Term::ReadLine;
@ -786,7 +787,7 @@ our $cmddef = {
monitor => [ __PACKAGE__, 'monitor', ['vmid']],
agent => [ "PVE::API2::Qemu", 'agent', ['vmid', 'command'],
agent => [ "PVE::API2::Qemu::Agent", 'agent', ['vmid', 'command'],
{ node => $nodename }, $print_agent_result ],
mtunnel => [ __PACKAGE__, 'mtunnel', []],