[pve-devel] [PATCH qemu-server] Add qm agent.

Dietmar Maurer dietmar at proxmox.com
Wed Nov 30 12:45:01 CET 2016


applied, but see comments inline:

>  __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'),

missing command line completion!

 completion => \&PVE::QemuServer::complete_vmid_running

> +	    command => {
> +		type => 'string',
> +		description => "The QGA command.",

should be an enum instead?

> +	    }
> +	},
> +    },
> +    returns => { type => 'string' },
> +    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);
> +

the following code looks wrong to me:

> +	my $res = '';
> +	eval {
> +	    $res = PVE::QemuServer::vm_mon_cmd($vmid, $param->{command});
> +	};
> +
> +	if (my $err = $@) {
> +		return "ERROR: $err";
> +	} else {
> +		my $res = ref($res) eq 'HASH' ? to_json($res) : $res;
> +		return "OK: $res\n";
> +	}

I would simple use:

 return PVE::QemuServer::vm_mon_cmd($vmid, $param->{command});


> +    }});
> +
> +__PACKAGE__->register_method({
>      name => 'resize_vm',
>      path => '{vmid}/resize',
>      method => 'PUT',
> diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
> index a0e0ba5..0599260 100755
> --- a/PVE/CLI/qm.pm
> +++ b/PVE/CLI/qm.pm
> @@ -529,6 +529,8 @@ our $cmddef = {
>  
>      monitor  => [ __PACKAGE__, 'monitor', ['vmid']],
>  
> +    agent  => [ "PVE::API2::Qemu", 'agent', ['vmid'], { node => $nodename }],

should be:

agent  => [ __PACKAGE__, 'agent', ['vmid'], { node => $nodename }],

?




More information about the pve-devel mailing list