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 000161FF137 for ; Tue, 17 Feb 2026 15:14:35 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3E44A2534; Tue, 17 Feb 2026 15:14:59 +0100 (CET) From: Daniel Kral To: pve-devel@lists.proxmox.com Subject: [RFC ha-manager 04/21] factor out common pve to ha resource type mapping Date: Tue, 17 Feb 2026 15:14:11 +0100 Message-ID: <20260217141437.584852-18-d.kral@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260217141437.584852-1-d.kral@proxmox.com> References: <20260217141437.584852-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: 1771337677214 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.019 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 Message-ID-Hash: 6BQBJYVOKGPXWHSEZV7FGZOLUCUHJLJS X-Message-ID-Hash: 6BQBJYVOKGPXWHSEZV7FGZOLUCUHJLJS 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 844ab1b1..bca5bb1c 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 do 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