public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Lorenz Stechauner <l.stechauner@proxmox.com>
Subject: [pve-devel] applied: [PATCH v2 manager] pve6to7: add check for guest and node description length
Date: Fri, 18 Jun 2021 16:52:09 +0200	[thread overview]
Message-ID: <bf4a5656-1919-8d3a-8640-7df0c667d373@proxmox.com> (raw)
In-Reply-To: <20210618133423.4014934-1-l.stechauner@proxmox.com>

On 18.06.21 15:34, Lorenz Stechauner wrote:
> Signed-off-by: Lorenz Stechauner <l.stechauner@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..





      reply	other threads:[~2021-06-18 14:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 13:34 [pve-devel] " Lorenz Stechauner
2021-06-18 14:52 ` Thomas Lamprecht [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf4a5656-1919-8d3a-8640-7df0c667d373@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=l.stechauner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal