]> git.proxmox.com Git - pve-manager.git/commitdiff
api: backup info: code/style cleanup/rework/modernization
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 15 Nov 2022 13:06:42 +0000 (14:06 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 15 Nov 2022 13:07:39 +0000 (14:07 +0100)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Cluster/BackupInfo.pm

index a36ba0452cca3608a2d59ce13a66a7f1403145fd..6d4cf57619a1b7771890f525b98d537836ea187b 100644 (file)
@@ -71,7 +71,7 @@ __PACKAGE__->register_method({
        check => ['perm', '/', ['Sys.Audit']],
     },
     parameters => {
-       additionalProperties => 0,
+       additionalProperties => 0,
        properties => {},
     },
     returns => {
@@ -103,26 +103,17 @@ __PACKAGE__->register_method({
 
        my $included_vmids = get_included_vmids();
        my $vmlist = PVE::Cluster::get_vmlist();
-       my @vmids = ( keys %{$vmlist->{ids}} );
 
-       # remove VMIDs to which the user has no permission to not leak infos
-       # like the guest name
-       my @allowed_vmids = grep {
-               $rpcenv->check($user, "/vms/$_", [ 'VM.Audit' ], 1);
-       } @vmids;
+       # remove VMIDs to which the user has no permission to not leak infos like the guest name
+       my @allowed_vmids = grep { $rpcenv->check($user, "/vms/$_", [ 'VM.Audit' ], 1) } keys $vmlist->{ids}->%*;
 
        my $result = [];
-
        for my $vmid (@allowed_vmids) {
-
            next if $included_vmids->{$vmid};
 
-           my $type = $vmlist->{ids}->{$vmid}->{type};
-           my $node = $vmlist->{ids}->{$vmid}->{node};
-
-           my $conf;
-           my $name = "";
+           my ($type, $node) = $vmlist->{ids}->{$vmid}->@{'type', 'node'};
 
+           my ($conf, $name);
            if ($type eq 'qemu') {
                $conf = PVE::QemuConfig->load_config($vmid, $node);
                $name = $conf->{name};
@@ -130,7 +121,7 @@ __PACKAGE__->register_method({
                $conf = PVE::LXC::Config->load_config($vmid, $node);
                $name = $conf->{hostname};
            } else {
-               die "VMID $vmid is neither Qemu nor LXC guest\n";
+               die "Unexpected error: unknown guest type for VMID $vmid, neither QEMU nor LXC\n";
            }
 
            push @{$result}, {