[pve-devel] applied: [PATCH v2 manager] pve6to7: add check for guest and node description length

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Jun 18 16:52:09 CEST 2021


On 18.06.21 15:34, Lorenz Stechauner wrote:
> Signed-off-by: Lorenz Stechauner <l.stechauner at proxmox.com>
> ---
> changes to v1:
> * using ::config_list() instead of ::vmstatus()
> 
>  PVE/CLI/pve6to7.pm | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
> 
> diff --git a/PVE/CLI/pve6to7.pm b/PVE/CLI/pve6to7.pm
> index fc779e4f..f9433028 100644
> --- a/PVE/CLI/pve6to7.pm
> +++ b/PVE/CLI/pve6to7.pm
> @@ -15,9 +15,11 @@ use PVE::Cluster;
>  use PVE::Corosync;
>  use PVE::INotify;
>  use PVE::JSONSchema;
> +use PVE::NodeConfig;
>  use PVE::RPCEnvironment;
>  use PVE::Storage;
>  use PVE::Tools qw(run_command split_list);
> +use PVE::QemuConfig;
>  use PVE::QemuServer;
>  use PVE::VZDump::Common;
>  
> @@ -660,6 +662,40 @@ sub check_custom_pool_roles {
>      }
>  }

>  
> +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");
> +	}

First I'd have recommend factoring above out in a helper, as it's repeated very similarly below another two times.

my sub check_max_length {
    my ($raw, $max_length, $warning) = @_;
    log_warn($warning) if defined($raw) && length($raw) > $max_length; 
}

check_max_length($conf->{description}, 64 * 1024, "description in config of node $node is too long! maximum will be 64k");


but I felt that joining all guests and all nodes each into a single warn was nicer, so I
reworked it a bit to first push all to an array and then output them joined, not the
nicest code but slightly shorter and the output looks good, IMO at least..






More information about the pve-devel mailing list