From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 326751FF186 for ; Fri, 1 Aug 2025 18:22:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1272F1E933; Fri, 1 Aug 2025 18:23:12 +0200 (CEST) From: Daniel Kral To: pve-devel@lists.proxmox.com Date: Fri, 1 Aug 2025 18:22:18 +0200 Message-ID: <20250801162230.296214-4-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250801162230.296214-1-d.kral@proxmox.com> References: <20250801162230.296214-1-d.kral@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1754065339850 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.014 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH ha-manager v2 03/12] tree-wide: pass optional parameters as hash values for for_each_rule helper X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Make call sites to the for_each_rule more readable and while at remove unnecessary variables in the helper body as well. Suggested-by: Thomas Lamprecht Signed-off-by: Daniel Kral --- src/PVE/API2/HA/Rules.pm | 6 ++---- src/PVE/HA/Rules.pm | 16 +++++++--------- src/PVE/HA/Rules/NodeAffinity.pm | 14 +++++--------- src/PVE/HA/Rules/ResourceAffinity.pm | 22 ++++++++-------------- 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/PVE/API2/HA/Rules.pm b/src/PVE/API2/HA/Rules.pm index 1591df28..b180d2ed 100644 --- a/src/PVE/API2/HA/Rules.pm +++ b/src/PVE/API2/HA/Rules.pm @@ -192,10 +192,8 @@ __PACKAGE__->register_method({ push @$res, $cfg; }, - { - type => $type, - sid => $resource, - }, + type => $type, + sid => $resource, ); return $res; diff --git a/src/PVE/HA/Rules.pm b/src/PVE/HA/Rules.pm index e5d12571..e2b77215 100644 --- a/src/PVE/HA/Rules.pm +++ b/src/PVE/HA/Rules.pm @@ -419,13 +419,13 @@ sub canonicalize : prototype($$$) { =head3 foreach_rule(...) -=head3 foreach_rule($rules, $func [, $opts]) +=head3 foreach_rule($rules, $func [, %opts]) Filters the given C<$rules> according to the C<$opts> and loops over the resulting rules in the order as defined in the section config and executes C<$func> with the parameters C>>. -The filter properties for C<$opts> are: +The following key-value pairs for C<$opts> as filter properties are: =over @@ -439,12 +439,10 @@ The filter properties for C<$opts> are: =cut -sub foreach_rule : prototype($$;$) { - my ($rules, $func, $opts) = @_; +sub foreach_rule : prototype($$;%) { + my ($rules, $func, %opts) = @_; - my $sid = $opts->{sid}; - my $type = $opts->{type}; - my $exclude_disabled_rules = $opts->{exclude_disabled_rules}; + my $sid = $opts{sid}; my @ruleids = sort { $rules->{order}->{$a} <=> $rules->{order}->{$b} @@ -455,8 +453,8 @@ sub foreach_rule : prototype($$;$) { next if !$rule; # skip invalid rules next if defined($sid) && !defined($rule->{resources}->{$sid}); - next if defined($type) && $rule->{type} ne $type; - next if $exclude_disabled_rules && exists($rule->{disable}); + next if defined($opts{type}) && $rule->{type} ne $opts{type}; + next if $opts{exclude_disabled_rules} && exists($rule->{disable}); $func->($rule, $ruleid); } diff --git a/src/PVE/HA/Rules/NodeAffinity.pm b/src/PVE/HA/Rules/NodeAffinity.pm index ee3ef985..09a8e67c 100644 --- a/src/PVE/HA/Rules/NodeAffinity.pm +++ b/src/PVE/HA/Rules/NodeAffinity.pm @@ -148,10 +148,8 @@ sub get_plugin_check_arguments { $result->{node_affinity_rules}->{$ruleid} = $rule; }, - { - type => 'node-affinity', - exclude_disabled_rules => 1, - }, + type => 'node-affinity', + exclude_disabled_rules => 1, ); return $result; @@ -231,11 +229,9 @@ my $get_resource_node_affinity_rule = sub { $node_affinity_rule = dclone($rule) if !$node_affinity_rule; }, - { - sid => $sid, - type => 'node-affinity', - exclude_disabled_rules => 1, - }, + sid => $sid, + type => 'node-affinity', + exclude_disabled_rules => 1, ); return $node_affinity_rule; diff --git a/src/PVE/HA/Rules/ResourceAffinity.pm b/src/PVE/HA/Rules/ResourceAffinity.pm index 6b5670ac..1d2ed1ed 100644 --- a/src/PVE/HA/Rules/ResourceAffinity.pm +++ b/src/PVE/HA/Rules/ResourceAffinity.pm @@ -92,10 +92,8 @@ sub get_plugin_check_arguments { $result->{positive_rules}->{$ruleid} = $rule if $rule->{affinity} eq 'positive'; $result->{negative_rules}->{$ruleid} = $rule if $rule->{affinity} eq 'negative'; }, - { - type => 'resource-affinity', - exclude_disabled_rules => 1, - }, + type => 'resource-affinity', + exclude_disabled_rules => 1, ); return $result; @@ -490,11 +488,9 @@ sub get_affinitive_resources : prototype($$) { $affinity_set->{$csid} = 1 if $csid ne $sid; } }, - { - sid => $sid, - type => 'resource-affinity', - exclude_disabled_rules => 1, - }, + sid => $sid, + type => 'resource-affinity', + exclude_disabled_rules => 1, ); return ($together, $separate); @@ -560,11 +556,9 @@ sub get_resource_affinity : prototype($$$) { } } }, - { - sid => $sid, - type => 'resource-affinity', - exclude_disabled_rules => 1, - }, + sid => $sid, + type => 'resource-affinity', + exclude_disabled_rules => 1, ); return ($together, $separate); -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel