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 7BEB21FF13C for ; Thu, 19 Mar 2026 17:41:21 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6A8FC63E7; Thu, 19 Mar 2026 17:41:27 +0100 (CET) From: Daniel Kral To: pve-devel@lists.proxmox.com Subject: [PATCH ha-manager v2 04/10] factor out common pve to ha resource type mapping Date: Thu, 19 Mar 2026 17:33:54 +0100 Message-ID: <20260319164047.642936-5-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260319164047.642936-1-d.kral@proxmox.com> References: <20260319164047.642936-1-d.kral@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1773938408068 X-SPAM-LEVEL: Spam detection results: 0 AWL -1.015 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.408 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.819 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.903 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 Message-ID-Hash: SLNAEX4OMSJFQBDGKREW7AVW2NKATJ3B X-Message-ID-Hash: SLNAEX4OMSJFQBDGKREW7AVW2NKATJ3B X-MailFrom: d.kral@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Daniel Kral --- src/PVE/HA/Config.pm | 8 +------- src/PVE/HA/Tools.pm | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/PVE/HA/Config.pm b/src/PVE/HA/Config.pm index 19eec2a4..cafbae8c 100644 --- a/src/PVE/HA/Config.pm +++ b/src/PVE/HA/Config.pm @@ -197,13 +197,7 @@ sub parse_sid { my $vmlist = PVE::Cluster::get_vmlist(); if (defined($vmlist->{ids}->{$name})) { my $vm_type = $vmlist->{ids}->{$name}->{type}; - if ($vm_type eq 'lxc') { - $type = 'ct'; - } elsif ($vm_type eq 'qemu') { - $type = 'vm'; - } else { - die "internal error"; - } + $type = PVE::HA::Tools::get_ha_resource_type($vm_type); $sid = "$type:$name"; } else { die "unable to detect SID from VMID - VM/CT $1 does not exist\n"; diff --git a/src/PVE/HA/Tools.pm b/src/PVE/HA/Tools.pm index 1fa53df8..26629fb5 100644 --- a/src/PVE/HA/Tools.pm +++ b/src/PVE/HA/Tools.pm @@ -289,6 +289,18 @@ sub has_min_version { return 1; } +sub get_ha_resource_type { + my ($pve_resource_type) = @_; + + if ($pve_resource_type eq 'lxc') { + return 'ct'; + } elsif ($pve_resource_type eq 'qemu') { + return 'vm'; + } else { + die "unknown PVE resource type '$pve_resource_type'"; + } +} + # bash auto completion helper # NOTE: we use PVE::HA::Config here without declaring an 'use' clause above as @@ -309,15 +321,10 @@ sub complete_sid { while (my ($vmid, $info) = each %{ $vmlist->{ids} }) { - my $sid; + my $type = eval { get_ha_resource_type($info->{type}) }; + next if $@; # silently ignore unknown pve types - if ($info->{type} eq 'lxc') { - $sid = "ct:$vmid"; - } elsif ($info->{type} eq 'qemu') { - $sid = "vm:$vmid"; - } else { - next; # should not happen - } + my $sid = "$type:$vmid"; next if $cfg->{ids}->{$sid}; -- 2.47.3