From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 244131FF164 for <inbox@lore.proxmox.com>; Fri, 25 Apr 2025 16:05:37 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 988D834AF6; Fri, 25 Apr 2025 16:05:43 +0200 (CEST) Message-ID: <6f5df6e4-2f78-4562-bc77-9fe992f0d9a6@proxmox.com> Date: Fri, 25 Apr 2025 16:05:39 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>, Daniel Kral <d.kral@proxmox.com> References: <20250325151254.193177-1-d.kral@proxmox.com> <20250325151254.193177-7-d.kral@proxmox.com> Content-Language: en-US From: Fiona Ebner <f.ebner@proxmox.com> In-Reply-To: <20250325151254.193177-7-d.kral@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL -0.038 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [colocation.pm] Subject: Re: [pve-devel] [PATCH ha-manager 05/15] rules: add colocation rule plugin X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Not much to add to Fabian's review :) Am 25.03.25 um 16:12 schrieb Daniel Kral: > diff --git a/src/PVE/HA/Rules/Colocation.pm b/src/PVE/HA/Rules/Colocation.pm > new file mode 100644 > index 0000000..808d48e > --- /dev/null > +++ b/src/PVE/HA/Rules/Colocation.pm > @@ -0,0 +1,391 @@ > +package PVE::HA::Rules::Colocation; > + > +use strict; > +use warnings; > + > +use Data::Dumper; > + > +use PVE::JSONSchema qw(get_standard_option); Missing include of PVE::Tools. Nit: I'd put a blank here to separate modules from different packages and modules from the same package. > +use PVE::HA::Tools; > + > +use base qw(PVE::HA::Rules); > + > +sub type { > + return 'colocation'; > +} > + > +sub properties { > + return { > + services => get_standard_option('pve-ha-resource-id-list'), > + affinity => { > + description => "Describes whether the services are supposed to be kept on separate" > + . " nodes, or are supposed to be kept together on the same node.", > + type => 'string', > + enum => ['separate', 'together'], > + optional => 0, > + }, > + strict => { > + description => "Describes whether the colocation rule is mandatory or optional.", > + type => 'boolean', > + optional => 0, > + }, > + } Style nit: missing semicolon Since we should move the property definitions to the base module once a second plugin re-uses them later: should we already declare 'services' and 'strict' in the base module to start out? Then we could implement the encode/decode part for 'services' there already. Less moving around or duplication later on. > +} > + > +sub options { > + return { > + services => { optional => 0 }, > + strict => { optional => 0 }, > + affinity => { optional => 0 }, > + comment => { optional => 1 }, > + }; > +}; > + > +sub decode_value { > + my ($class, $type, $key, $value) = @_; > + > + if ($key eq 'services') { > + my $res = {}; > + > + for my $service (PVE::Tools::split_list($value)) { > + if (PVE::HA::Tools::pve_verify_ha_resource_id($service)) { > + $res->{$service} = 1; > + } > + } > + > + return $res; > + } > + > + return $value; > +} > + > +sub encode_value { > + my ($class, $type, $key, $value) = @_; > + > + if ($key eq 'services') { > + PVE::HA::Tools::pve_verify_ha_resource_id($_) for (keys %$value); Style nit: [I] febner@dev8 /usr/share/perl5/PVE> ag "for keys" | wc -l 28 [I] febner@dev8 /usr/share/perl5/PVE> ag "for \(keys" | wc -l 0 > + > + return join(',', keys %$value); > + } > + > + return $value; > +} > + ---snip 8<--- > +=head3 check_service_count($rules) > + > +Returns a list of conflicts caused by colocation rules, which do not have > +enough services in them, defined in C<$rules>. > + > +If there are no conflicts, the returned list is empty. > + > +=cut > + > +sub check_services_count { > + my ($rules) = @_; > + > + my $conflicts = []; > + > + foreach_colocation_rule($rules, sub { > + my ($rule, $ruleid) = @_; > + > + push @$conflicts, $ruleid if (scalar(keys %{$rule->{services}}) < 2); Style nit: parentheses for post-if _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel