]> git.proxmox.com Git - pve-manager.git/commitdiff
pve6to7: re-work output of description length check and add passes too
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Jun 2021 14:49:22 +0000 (16:49 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 18 Jun 2021 14:49:22 +0000 (16:49 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/CLI/pve6to7.pm

index d72fd4909e0ad369ee9fdb2f3ef59d4c4ef5a603..80309ac725262086573ba0e7c4f1005623802d22 100644 (file)
@@ -662,37 +662,43 @@ sub check_custom_pool_roles {
     }
 }
 
+my sub check_max_length {
+    my ($raw, $max_length, $warning) = @_;
+    log_warn($warning) if defined($raw) && length($raw) > $max_length; 
+}
+
 sub check_description_lengths {
     log_info("Checking node and guest description/note legnth..");
 
-    my $nodes = PVE::Cluster::get_nodelist();;
-    foreach my $node (@$nodes) {
-       my $conf = PVE::NodeConfig::load_config($node);
-       my $desc = $conf->{description};
-       next if !defined($desc);
-       if (length($desc) > 64 * 1024) {
-           log_warn("Description of node $node is too long! - maximum will be 64k");
-       }
-    }
+    my @affected_nodes = grep {
+       my $desc = PVE::NodeConfig::load_config($_)->{desc};
+       defined($desc) && length($desc) > 64 * 1024
+    } PVE::Cluster::get_nodelist();
 
-    my $lxcs = PVE::LXC::config_list();
-    foreach my $vmid (keys %$lxcs) {
-       my $conf = PVE::LXC::Config->load_config($vmid);
-       my $desc = $conf->{description};
-       next if !defined($desc);
-       if (length($desc) > 8 * 1024) {
-           log_warn("Description of guest $vmid is too long! - maximum will be 8k");
-       }
+    if (scalar(@affected_nodes) > 0) {
+       log_warn("Node config description of the following nodes too long for new limit of 64 KiB:\n    "
+           . join(', ', @affected_nodes));
+    } else {
+       log_pass("All node config descriptions fit in the new limit of 64 KiB");
     }
 
+    my $affected_guests = [];
+
+    my $cts = PVE::LXC::config_list();
+    for my $vmid (sort { $a <=> $b } keys %$cts) {
+       my $desc = PVE::LXC::Config->load_config($vmid)->{description};
+       push @$affected_guests, "CT $vmid" if defined($desc) && length($desc) > 8 * 1024;
+    }
     my $vms = PVE::QemuServer::config_list();
-    foreach my $vmid (keys %$vms) {
-       my $conf = PVE::QemuConfig->load_config($vmid);
-       my $desc = $conf->{description};
-       next if !defined($desc);
-       if (length($desc) > 8 * 1024) {
-           log_warn("Description of guest $vmid is too long! - maximum will be 8k");
-       }
+    for my $vmid (sort { $a <=> $b } keys %$vms) {
+       my $desc = PVE::QemuConfig->load_config($vmid)->{description};
+       push @$affected_guests, "VM $vmid" if defined($desc) && length($desc) > 8 * 1024;
+    }
+    if (scalar($affected_guests->@*) > 0) {
+       log_warn("Node config description of the following nodes too long for new limit of 64 KiB:\n"
+           ."    * " . join("\n    * ", $affected_guests->@*));
+    } else {
+       log_pass("All guest config descriptions fit in the new limit of 8 KiB");
     }
 }