[pve-devel] [PATCH: proxmox-widget-toolkit] parse_task_upid: Allow additional (optional) task_id field

2019-12-17 Thread dietmar
From: Dietmar Maurer 

We need that if tasks runs inside multi-threaded applications (several
tasks inside one process).
---
 Utils.js | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/Utils.js b/Utils.js
index 1fa6999..6d1b24c 100644
--- a/Utils.js
+++ b/Utils.js
@@ -589,17 +589,20 @@ Ext.define('Proxmox.Utils', { utilities: {
 parse_task_upid: function(upid) {
var task = {};
 
-   var res = 
upid.match(/^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/);
+   var res = 
upid.match(/^UPID:([^\s:]+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):(([0-9A-Fa-f]{8,16}):)?([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/);
if (!res) {
throw "unable to parse upid '" + upid + "'";
}
task.node = res[1];
task.pid = parseInt(res[2], 16);
task.pstart = parseInt(res[3], 16);
-   task.starttime = parseInt(res[4], 16);
-   task.type = res[5];
-   task.id = res[6];
-   task.user = res[7];
+   if (res[5] !== undefined) {
+   task.task_id = parseInt(res[5], 16);
+   }
+   task.starttime = parseInt(res[6], 16);
+   task.type = res[7];
+   task.id = res[8];
+   task.user = res[9];
 
task.desc = Proxmox.Utils.format_task_description(task.type, task.id);
 
-- 
2.20.1

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


[pve-devel] applied: [PATCH: proxmox-widget-toolkit] parse_task_upid: Allow additional (optional) task_id field

2019-12-17 Thread Thomas Lamprecht
On 12/17/19 11:46 AM, diet...@proxmox.com wrote:
> From: Dietmar Maurer 
> 
> We need that if tasks runs inside multi-threaded applications (several
> tasks inside one process).
> ---
>  Utils.js | 13 -
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 

applied, thanks!

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


[pve-devel] applied: [PATCH proxmox-widget-toolkit] task viewer: add new taks_id field as optional row entry

2019-12-17 Thread Thomas Lamprecht
Signed-off-by: Thomas Lamprecht 
---
 window/TaskViewer.js | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/window/TaskViewer.js b/window/TaskViewer.js
index d3133f9..347542e 100644
--- a/window/TaskViewer.js
+++ b/window/TaskViewer.js
@@ -137,6 +137,9 @@ Ext.define('Proxmox.window.TaskViewer', {
header: gettext('Process ID'),
required: true
},
+   task_id: {
+   header: gettext('Task ID'),
+   },
starttime: {
header: gettext('Start Time'),
required: true,
-- 
2.20.1


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


Re: [pve-devel] [RFC manager 1/2] api: backup: Add endpoint for disk included status

2019-12-17 Thread Dominic Jäger
Hi,

the attached test cases show some small problems with uninitialized values.
Please use them only in a test environment. It might destroy pools, VMs or 
backup jobs.

On Thu, Dec 12, 2019 at 11:27:44AM +0100, Aaron Lauterer wrote:
> + my $vzconf = cfs_read_file('vzdump.cron');
> + my $jobs = $vzconf->{jobs} || [];
> + my $job;
> +
> + foreach my $j (@$jobs) {
> + $job = $j if $j->{id} eq $param->{id};
> + }
Maybe something like s/$jobs/$cronjobs/ or required_id=$param->{id}? If we 
could make
the difference between j, job, jobs, $vzconf->{jobs} a little clearer that 
would be nice.
> + raise_param_exc({ id => "No such job '$param->{id}'" }) if !$job;
> +
> + my @vmids;
> + my $vmlist = PVE::Cluster::get_vmlist();
> +
> + # get VMIDs from pool or selected individual guests
> + if ($job->{pool}) {
> + @vmids = 
> @{PVE::API2Tools::get_resource_pool_guest_members($job->{pool})};
> + } elsif ($job->{vmid}) {
> + @vmids = PVE::Tools::split_list(extract_param($job, 'vmid'));
> + }
When reading this I would have to know the whole context to know why there is 
no else.
I personally would rather write

if ($job->{pool}) {
...
} else {
# now $job->{vmid} is defined
}

or as you did further below

if () {
} elsif () {
} else {
 # must not happen, throw some error
}
> +
> + # get excluded guests
> + my @exclude = PVE::Tools::split_list(extract_param($job, 'exclude'));
> + @exclude = @{PVE::VZDump::check_vmids(@exclude)};
> + @vmids = @{PVE::VZDump::check_vmids(@vmids)};
> +
> + my $excludehash = { map { $_ => 1 } @exclude };
> +
> + # no list of guests? (from pool or manually)
> + # get all except excluded
> + if (!@vmids) {
> + if ($job->{all} && $job->{node}) {
> + foreach my $id (keys %{ $vmlist->{ids} }) {
> + push @vmids, $id
> + if $vmlist->{ids}->{$id}->{node} eq $job->{node} && 
> !$excludehash->{$id};
> + }
> + } elsif ($job->{all}) {
> + foreach my $id (keys %{ $vmlist->{ids} }) {
> + push @vmids, $id if !$excludehash->{$id};
> + }
Same question as elsif above

> + }
> + }
> +
> + @vmids = sort {$a <=> $b} @vmids;
> +
> + # prepare API response
This is already clear from the variable name for me.

> + my $result = {
> + children => [],
> + leaf => 0,
> + };
> +
> + foreach (@vmids) {
> + my $id = $_;
> + my $type = $vmlist->{ids}->{$id}->{type};
> + my $node = $vmlist->{ids}->{$id}->{node};
> +
> + my $guest = {
> + id => $id,
> + children => [],
> + leaf => 0,
> + };
> +
> + if ($type eq 'qemu') {
> + my $conf = PVE::QemuConfig->load_config($id, $node);
> +
> + $guest->{id} = $guest->{id} . " " . $conf->{name};
> + $guest->{type} = 'VM';
> +
> + PVE::QemuServer::foreach_drive($conf, sub {
> + my ($key, $attr) = @_;
> +
> + return if PVE::QemuServer::drive_is_cdrom($attr);
> +
> + my $status = 'true';
> +
> + $status = 'false' if (exists($attr->{backup}) && 
> !$attr->{backup});
> +
> + my $disk = {
> + id => $key . ' - '. $attr->{file},
> + status => $status,
> + leaf => 1,
> + };
> + push @{$guest->{children}}, $disk;
> + });
> + } elsif ($type eq 'lxc') {
> + my $conf = PVE::LXC::Config->load_config($id, $node);
> +
> + $guest->{id} = $guest->{id} . " " . $conf->{hostname};
> + $guest->{type} = 'CT';
> +
> + PVE::LXC::Config->foreach_mountpoint($conf, sub {
> + my ($key, $attr) = @_;
> +
> + my $status = 'false';
> +
> + $status = 'true' if ($key eq 'rootfs' || 
> (exists($attr->{backup}) && $attr->{backup}));
> + $status = 'not possible' if ($attr->{type} ne 'volume');
> +
> + my $disk = {
> + id => $key . ' - '. $attr->{volume},
> + status => $status,
> + leaf => 1,
> + };
> + push @{$guest->{children}}, $disk;
> + });
> + } else {
> + die "VMID $id is not Qemu nor LXC guest\n";
Neither ... nor ... ?
Nontheless, this is whole section is very clearly written IMO :)
> + }
> +
> + push @{$result->{children}}, $guest;
> + }
> +
> + return $result;
> +}});
>  1;
> -- 
> 2.20.1
> 
> 
> ___
> pve-devel mailing list
> pve-devel@pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>