Re: [pve-devel] [PATCH qemu-server 7/7] add new guest-agent commands

2018-02-13 Thread Thomas Lamprecht
On 2/13/18 4:47 PM, Dominik Csapak wrote:
> between qemu 2.9 and 2.11 there were added some new commands,
> the guest agent inside the vm has to support these
> 

What happens if it does not? Probably way cheaper to just let it
error out, than probing the qga version before, I guess?

> Signed-off-by: Dominik Csapak 
> ---
>  PVE/API2/Qemu/Agent.pm | 17 +
>  1 file changed, 17 insertions(+)
> 
> diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm
> index 24b44a9..40d9ff7 100644
> --- a/PVE/API2/Qemu/Agent.pm
> +++ b/PVE/API2/Qemu/Agent.pm
> @@ -28,6 +28,11 @@ my $guest_agent_commands = [
>  'suspend-ram',
>  'suspend-disk',
>  'shutdown',
> +# added since qemu 2.9
> +'get-host-name',
> +'get-osinfo',
> +'get-users',
> +'get-timezone',
>  ];
>  
>  # properties for each command, optional
> @@ -57,6 +62,18 @@ my $ga_cmd_properties =  {
>  'info' => {
>   method => 'GET',
>  },
> +'get-host-name' => {
> + method => 'GET',
> +},
> +'get-osinfo' => {
> + method => 'GET',
> +},
> +'get-users' => {
> + method => 'GET',
> +},
> +'get-timezone' => {
> + method => 'GET',
> +},
>  };
>  
>  __PACKAGE__->register_method({
> 


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


Re: [pve-devel] [PATCH qemu-server 4/7] make an api call for each guest agent command

2018-02-13 Thread Thomas Lamprecht
On 2/13/18 4:47 PM, Dominik Csapak wrote:
> with a 'register_command' sub, which generates an api call
> we call it for each command in the list, and one time for
> the old general {vmid}/agent endpoint (for compatibility)
> 
> permissions/methods are the same as previously, but can
> be overriden with an entry in $ga_cmd_properties
> 
> Signed-off-by: Dominik Csapak 
> ---
>  PVE/API2/Qemu/Agent.pm | 99 
> --
>  1 file changed, 71 insertions(+), 28 deletions(-)
> 
> diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm
> index 437d3f6..9d87b43 100644
> --- a/PVE/API2/Qemu/Agent.pm
> +++ b/PVE/API2/Qemu/Agent.pm
> @@ -9,6 +9,8 @@ use PVE::QemuServer;
>  
>  use base qw(PVE::RESTHandler);
>  
> +# list of commands
> +# will generate one api endpoint per command
>  my $guest_agent_commands = [
>  'ping',
>  'get-time',
> @@ -28,49 +30,90 @@ my $guest_agent_commands = [
>  '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 => {
> +# properties for each command, optional
> +# can has

What's with the early broken line? If we'd keep the semantics here I'd swap
the whole with:

# optionally set perms (default: VM.Monitor) or method (default: POST) property

To make a short concise single line comment.

> +# 'method': e.g. GET/POST
> +# 'perms': either a string like 'VM.Montior' or an array of such strings
> +#   or a permission object

s/Montior/Monitor/

> +my $ga_cmd_properties =  {};
> +
> +sub register_command {
> +my ($class, $command, $method, $perm) = @_;
> +
> +$method //= 'POST';
> +my $permission;
> +if (!$perm) {
> + $permission = { check => [ 'perm', '/vms/{vmid}', [ 'VM.Monitor' ]]};
> +} elsif (ref($perm) eq 'SCALAR') {
> + $permission = { check => [ 'perm', '/vms/{vmid}', [ $perm ]]};
> +} elsif (ref($perm) eq 'ARRAY') {
> + $permission = { check => [ 'perm', '/vms/{vmid}', $perm ]};
> +} elsif (ref($perm) eq 'HASH') {
> + $permission = $perm;
> +} else {
> + die 'invalid permissions given';
> +}

That's a bit of code which currently does not get used once after
the whole series got applied?
You sure we need this all? If so either add the respective permission
changes together if some monitor commands would need them, or just add
a very simplified version which accepts either string (falling back to
VM.Monitor) or full hash for now?

Rest looks OK.

> +
> +my $parameters = {
>   additionalProperties => 0,
>   properties => {
>   node => get_standard_option('pve-node'),
>   vmid => get_standard_option('pve-vmid', {
> -   completion => \::QemuServer::complete_vmid_running }),
> + completion => \::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 $description = "Execute Qemu Guest Agent commands.";
> +my $name = 'agent';
> +$command //= '';
> +
> +if ($command ne '') {
> + $description = "Execute $command.";
> + $name = $command;
> + delete $parameters->{properties}->{command};
> +}
> +
> +__PACKAGE__->register_method({
> + name => $name,
> + path => $command,
> + method => $method,
> + protected => 1,
> + proxyto => 'node',
> + description => $description,
> + permissions => $permission,
> + parameters => $parameters,
> + returns => {
> + type => 'object',
> + description => "Returns an object with a single `result` property.",
> + },
> + code => sub {
> + my ($param) = @_;
> +
> + my $vmid = $param->{vmid};
>  
> - my $vmid = $param->{vmid};
> + my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM 
> exists
>  
> - 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);
>  
> - 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} // $command;
> + my $res = PVE::QemuServer::vm_mon_cmd($vmid, "guest-$cmd");
>  
> - 

Re: [pve-devel] [PATCH qemu-server 6/7] change some guest agent commands to GET api calls

2018-02-13 Thread Thomas Lamprecht
On 2/13/18 4:47 PM, Dominik Csapak wrote:
> Signed-off-by: Dominik Csapak 
> ---
>  PVE/API2/Qemu/Agent.pm | 24 +++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm
> index 2743595..24b44a9 100644
> --- a/PVE/API2/Qemu/Agent.pm
> +++ b/PVE/API2/Qemu/Agent.pm
> @@ -35,7 +35,29 @@ my $guest_agent_commands = [
>  # 'method': e.g. GET/POST
>  # 'perms': either a string like 'VM.Montior' or an array of such strings
>  #   or a permission object
> -my $ga_cmd_properties =  {};
> +my $ga_cmd_properties =  {
> +'network-get-interfaces' => {
> + method => 'GET',
> +},
> +'get-vcpus' => {
> + method => 'GET',
> +},
> +'get-fsinfo' => {
> + method => 'GET',
> +},
> +'get-memory-blocks' => {
> + method => 'GET',
> +},
> +'get-memory-block-info' => {
> + method => 'GET',
> +},
> +'get-time' => {
> + method => 'GET',
> +},
> +'info' => {
> + method => 'GET',
> +},
> +};
>  

Hmm, how about not falling back to 'POST' method as default but cry
and list here _all_ commands with the respective method?

Better even, change $guest_agent_commands to a hash doing exactly
this, then you do not semi-duplicate command names, as all known ones
are defined there and you could use 'keys $guest_agent_commands' to get
the command array.

>  __PACKAGE__->register_method({
>  name => 'index',
> 


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


Re: [pve-devel] [PATCH qemu-server 1/7] improve PVE/API2/Makefile

2018-02-13 Thread Thomas Lamprecht
On 2/13/18 4:47 PM, Dominik Csapak wrote:
> remove unnecessary SOURCES variable and add the directory
> 
> Signed-off-by: Dominik Csapak 
> ---
>  PVE/API2/Makefile | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/PVE/API2/Makefile b/PVE/API2/Makefile
> index 3fd85e2..b438448 100644
> --- a/PVE/API2/Makefile
> +++ b/PVE/API2/Makefile
> @@ -1,6 +1,4 @@
> -SOURCES=   \
> - Qemu.pm 
> -

Rather use ${SOURCES} below, instead of hard coding Qemu.pm there less visibly,
mirroring the Makefile one directory level above (PVE/Makefile)?

>  .PHONY: install
>  install:
> + install -d -m 0755 ${DESTDIR}${PERLDIR}/PVE/API2
>   install -D -m 0644 Qemu.pm ${DESTDIR}${PERLDIR}/PVE/API2/Qemu.pm
> 


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH qemu-server 2/7] add agent flag to vm status api call

2018-02-13 Thread Dominik Csapak
so that we can check in the gui if we have the agent set without
having to load the whole config

Signed-off-by: Dominik Csapak 
---
 PVE/API2/Qemu.pm | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index b277a26..6c9ede9 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1760,6 +1760,8 @@ __PACKAGE__->register_method({
 
$status->{spice} = 1 if 
PVE::QemuServer::vga_conf_has_spice($conf->{vga});
 
+   $status->{agent} = 1 if $conf->{agent};
+
return $status;
 }});
 
-- 
2.11.0


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH qemu-server 1/7] improve PVE/API2/Makefile

2018-02-13 Thread Dominik Csapak
remove unnecessary SOURCES variable and add the directory

Signed-off-by: Dominik Csapak 
---
 PVE/API2/Makefile | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/PVE/API2/Makefile b/PVE/API2/Makefile
index 3fd85e2..b438448 100644
--- a/PVE/API2/Makefile
+++ b/PVE/API2/Makefile
@@ -1,6 +1,4 @@
-SOURCES=   \
-   Qemu.pm 
-
 .PHONY: install
 install:
+   install -d -m 0755 ${DESTDIR}${PERLDIR}/PVE/API2
install -D -m 0644 Qemu.pm ${DESTDIR}${PERLDIR}/PVE/API2/Qemu.pm
-- 
2.11.0


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH qemu-server 0/7] improve qemu-guest-agent api

2018-02-13 Thread Dominik Csapak
this series aims to improve the guest agent api (but maintains compatibility)
by adding an api call for each command, making some commands
a GET call instead of POST (important for the webui)
and adds some new commands added in qemu since 2.9

also this splits the code from Qemu.pm in its own file

Dominik Csapak (7):
  improve PVE/API2/Makefile
  add agent flag to vm status api call
  move guest agent api call to its own file
  make an api call for each guest agent command
  add an guest agent index call
  change some guest agent commands to GET api calls
  add new guest-agent commands

 PVE/API2/Makefile  |   5 +-
 PVE/API2/Qemu.pm   |  72 ++
 PVE/API2/Qemu/Agent.pm | 196 +
 PVE/API2/Qemu/Makefile |   6 ++
 PVE/CLI/qm.pm  |   3 +-
 5 files changed, 214 insertions(+), 68 deletions(-)
 create mode 100644 PVE/API2/Qemu/Agent.pm
 create mode 100644 PVE/API2/Qemu/Makefile

-- 
2.11.0


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH qemu-server 4/7] make an api call for each guest agent command

2018-02-13 Thread Dominik Csapak
with a 'register_command' sub, which generates an api call
we call it for each command in the list, and one time for
the old general {vmid}/agent endpoint (for compatibility)

permissions/methods are the same as previously, but can
be overriden with an entry in $ga_cmd_properties

Signed-off-by: Dominik Csapak 
---
 PVE/API2/Qemu/Agent.pm | 99 --
 1 file changed, 71 insertions(+), 28 deletions(-)

diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm
index 437d3f6..9d87b43 100644
--- a/PVE/API2/Qemu/Agent.pm
+++ b/PVE/API2/Qemu/Agent.pm
@@ -9,6 +9,8 @@ use PVE::QemuServer;
 
 use base qw(PVE::RESTHandler);
 
+# list of commands
+# will generate one api endpoint per command
 my $guest_agent_commands = [
 'ping',
 'get-time',
@@ -28,49 +30,90 @@ my $guest_agent_commands = [
 '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 => {
+# properties for each command, optional
+# can has
+# 'method': e.g. GET/POST
+# 'perms': either a string like 'VM.Montior' or an array of such strings
+# or a permission object
+my $ga_cmd_properties =  {};
+
+sub register_command {
+my ($class, $command, $method, $perm) = @_;
+
+$method //= 'POST';
+my $permission;
+if (!$perm) {
+   $permission = { check => [ 'perm', '/vms/{vmid}', [ 'VM.Monitor' ]]};
+} elsif (ref($perm) eq 'SCALAR') {
+   $permission = { check => [ 'perm', '/vms/{vmid}', [ $perm ]]};
+} elsif (ref($perm) eq 'ARRAY') {
+   $permission = { check => [ 'perm', '/vms/{vmid}', $perm ]};
+} elsif (ref($perm) eq 'HASH') {
+   $permission = $perm;
+} else {
+   die 'invalid permissions given';
+}
+
+my $parameters = {
additionalProperties => 0,
properties => {
node => get_standard_option('pve-node'),
vmid => get_standard_option('pve-vmid', {
-   completion => \::QemuServer::complete_vmid_running }),
+   completion => \::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 $description = "Execute Qemu Guest Agent commands.";
+my $name = 'agent';
+$command //= '';
+
+if ($command ne '') {
+   $description = "Execute $command.";
+   $name = $command;
+   delete $parameters->{properties}->{command};
+}
+
+__PACKAGE__->register_method({
+   name => $name,
+   path => $command,
+   method => $method,
+   protected => 1,
+   proxyto => 'node',
+   description => $description,
+   permissions => $permission,
+   parameters => $parameters,
+   returns => {
+   type => 'object',
+   description => "Returns an object with a single `result` property.",
+   },
+   code => sub {
+   my ($param) = @_;
+
+   my $vmid = $param->{vmid};
 
-   my $vmid = $param->{vmid};
+   my $conf = PVE::QemuConfig->load_config ($vmid); # check if VM 
exists
 
-   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);
 
-   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} // $command;
+   my $res = PVE::QemuServer::vm_mon_cmd($vmid, "guest-$cmd");
 
-   my $cmd = $param->{command};
+   return { result => $res };
+   }});
+}
 
-   my $res = PVE::QemuServer::vm_mon_cmd($vmid, "guest-$cmd");
+# old {vmid}/agent POST endpoint, here for compatibility
+__PACKAGE__->register_command();
 
-   return { result => $res };
-}});
+for my $cmd (@$guest_agent_commands) {
+my $props = $ga_cmd_properties->{$cmd} // {};
+__PACKAGE__->register_command($cmd, $props->{method}, $props->{perms});
+}
 
 1;
-- 
2.11.0


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH qemu-server 6/7] change some guest agent commands to GET api calls

2018-02-13 Thread Dominik Csapak
Signed-off-by: Dominik Csapak 
---
 PVE/API2/Qemu/Agent.pm | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm
index 2743595..24b44a9 100644
--- a/PVE/API2/Qemu/Agent.pm
+++ b/PVE/API2/Qemu/Agent.pm
@@ -35,7 +35,29 @@ my $guest_agent_commands = [
 # 'method': e.g. GET/POST
 # 'perms': either a string like 'VM.Montior' or an array of such strings
 # or a permission object
-my $ga_cmd_properties =  {};
+my $ga_cmd_properties =  {
+'network-get-interfaces' => {
+   method => 'GET',
+},
+'get-vcpus' => {
+   method => 'GET',
+},
+'get-fsinfo' => {
+   method => 'GET',
+},
+'get-memory-blocks' => {
+   method => 'GET',
+},
+'get-memory-block-info' => {
+   method => 'GET',
+},
+'get-time' => {
+   method => 'GET',
+},
+'info' => {
+   method => 'GET',
+},
+};
 
 __PACKAGE__->register_method({
 name => 'index',
-- 
2.11.0


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH qemu-server 5/7] add an guest agent index call

2018-02-13 Thread Dominik Csapak
Signed-off-by: Dominik Csapak 
---
 PVE/API2/Qemu/Agent.pm | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm
index 9d87b43..2743595 100644
--- a/PVE/API2/Qemu/Agent.pm
+++ b/PVE/API2/Qemu/Agent.pm
@@ -37,6 +37,44 @@ my $guest_agent_commands = [
 # or a permission object
 my $ga_cmd_properties =  {};
 
+__PACKAGE__->register_method({
+name => 'index',
+path => '',
+proxyto => 'node',
+method => 'GET',
+description => "Qemu Agent command index.",
+permissions => {
+   user => 'all',
+},
+parameters => {
+   additionalProperties => 1,
+   properties => {
+   node => get_standard_option('pve-node'),
+   vmid => get_standard_option('pve-vmid', {
+   completion => \::QemuServer::complete_vmid_running }),
+   },
+},
+returns => {
+   type => 'array',
+   items => {
+   type => "object",
+   properties => {},
+   },
+   links => [ { rel => 'child', href => '{name}' } ],
+   description => "Returns the list of Qemu Agent commands",
+},
+code => sub {
+   my ($param) = @_;
+
+   my $result = [];
+
+   for my $cmd (@$guest_agent_commands) {
+   push @$result, { name => $cmd };
+   }
+
+   return $result;
+}});
+
 sub register_command {
 my ($class, $command, $method, $perm) = @_;
 
-- 
2.11.0


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH qemu-server 7/7] add new guest-agent commands

2018-02-13 Thread Dominik Csapak
between qemu 2.9 and 2.11 there were added some new commands,
the guest agent inside the vm has to support these

Signed-off-by: Dominik Csapak 
---
 PVE/API2/Qemu/Agent.pm | 17 +
 1 file changed, 17 insertions(+)

diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm
index 24b44a9..40d9ff7 100644
--- a/PVE/API2/Qemu/Agent.pm
+++ b/PVE/API2/Qemu/Agent.pm
@@ -28,6 +28,11 @@ my $guest_agent_commands = [
 'suspend-ram',
 'suspend-disk',
 'shutdown',
+# added since qemu 2.9
+'get-host-name',
+'get-osinfo',
+'get-users',
+'get-timezone',
 ];
 
 # properties for each command, optional
@@ -57,6 +62,18 @@ my $ga_cmd_properties =  {
 'info' => {
method => 'GET',
 },
+'get-host-name' => {
+   method => 'GET',
+},
+'get-osinfo' => {
+   method => 'GET',
+},
+'get-users' => {
+   method => 'GET',
+},
+'get-timezone' => {
+   method => 'GET',
+},
 };
 
 __PACKAGE__->register_method({
-- 
2.11.0


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH qemu-server 3/7] move guest agent api call to its own file

2018-02-13 Thread Dominik Csapak
so we do not pollute the Qemu.pm too much

Signed-off-by: Dominik Csapak 
---
 PVE/API2/Makefile  |  1 +
 PVE/API2/Qemu.pm   | 70 --
 PVE/API2/Qemu/Agent.pm | 76 ++
 PVE/API2/Qemu/Makefile |  6 
 PVE/CLI/qm.pm  |  3 +-
 5 files changed, 91 insertions(+), 65 deletions(-)
 create mode 100644 PVE/API2/Qemu/Agent.pm
 create mode 100644 PVE/API2/Qemu/Makefile

diff --git a/PVE/API2/Makefile b/PVE/API2/Makefile
index b438448..c2d01be 100644
--- a/PVE/API2/Makefile
+++ b/PVE/API2/Makefile
@@ -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
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 6c9ede9..5051cc9 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -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 => \::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',
diff --git a/PVE/API2/Qemu/Agent.pm b/PVE/API2/Qemu/Agent.pm
new file mode 100644
index 000..437d3f6
--- /dev/null
+++ b/PVE/API2/Qemu/Agent.pm
@@ -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 => \::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 

[pve-devel] applied: [PATCH widget-toolkit] rename pve(Show|Hide)Help events

2018-02-13 Thread Dominik Csapak

applied

___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


Re: [pve-devel] [PATCH widget-toolkit] rename pve(Show|Hide)Help events

2018-02-13 Thread Thomas Lamprecht
On 2/13/18 2:22 PM, Dominik Csapak wrote:
> we renamed them in the helpButton, we also have to rename them here
> this prevented the help button to show up in the vm/ct creation wizard
> 
> Signed-off-by: Dominik Csapak 
> ---
>  panel/InputPanel.js | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/panel/InputPanel.js b/panel/InputPanel.js
> index 4add54d..e3a2520 100644
> --- a/panel/InputPanel.js
> +++ b/panel/InputPanel.js
> @@ -5,12 +5,12 @@ Ext.define('Proxmox.panel.InputPanel', {
>   activate: function() {
>   // notify owning container that it should display a help button
>   if (this.onlineHelp) {
> - Ext.GlobalEvents.fireEvent('pveShowHelp', this.onlineHelp);
> + Ext.GlobalEvents.fireEvent('proxmoxShowHelp', this.onlineHelp);
>   }
>   },
>   deactivate: function() {
>   if (this.onlineHelp) {
> - Ext.GlobalEvents.fireEvent('pveHideHelp', this.onlineHelp);
> + Ext.GlobalEvents.fireEvent('proxmoxHideHelp', this.onlineHelp);
>   }
>   }
>  },
> 

Reviewed-by: Thomas Lamprecht 

___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH widget-toolkit] rename pve(Show|Hide)Help events

2018-02-13 Thread Dominik Csapak
we renamed them in the helpButton, we also have to rename them here
this prevented the help button to show up in the vm/ct creation wizard

Signed-off-by: Dominik Csapak 
---
 panel/InputPanel.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/panel/InputPanel.js b/panel/InputPanel.js
index 4add54d..e3a2520 100644
--- a/panel/InputPanel.js
+++ b/panel/InputPanel.js
@@ -5,12 +5,12 @@ Ext.define('Proxmox.panel.InputPanel', {
activate: function() {
// notify owning container that it should display a help button
if (this.onlineHelp) {
-   Ext.GlobalEvents.fireEvent('pveShowHelp', this.onlineHelp);
+   Ext.GlobalEvents.fireEvent('proxmoxShowHelp', this.onlineHelp);
}
},
deactivate: function() {
if (this.onlineHelp) {
-   Ext.GlobalEvents.fireEvent('pveHideHelp', this.onlineHelp);
+   Ext.GlobalEvents.fireEvent('proxmoxHideHelp', this.onlineHelp);
}
}
 },
-- 
2.11.0


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


[pve-devel] [PATCH docs] fix typo in api viewer

2018-02-13 Thread Dominik Csapak
authententification -> authentication
authententicated -> authenticated

Signed-off-by: Dominik Csapak 
---
 api-viewer/PVEAPI.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/api-viewer/PVEAPI.js b/api-viewer/PVEAPI.js
index 394dda1..409214d 100644
--- a/api-viewer/PVEAPI.js
+++ b/api-viewer/PVEAPI.js
@@ -212,9 +212,9 @@ Ext.onReady(function() {
if (info.permissions.user) {
if (!info.permissions.description) {
if (info.permissions.user === 'world') {
-   permhtml += "Accessible without any 
authententification.";
+   permhtml += "Accessible without any 
authentication.";
} else if (info.permissions.user === 'all') {
-   permhtml += "Accessible by all authententicated 
users.";
+   permhtml += "Accessible by all authenticated 
users.";
} else {
permhtml += 'Onyl accessible by user "' + 
info.permissions.user + '"';
-- 
2.11.0


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel