all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Daniel Kral <d.kral@proxmox.com>
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	[thread overview]
Message-ID: <20260319164047.642936-5-d.kral@proxmox.com> (raw)
In-Reply-To: <20260319164047.642936-1-d.kral@proxmox.com>

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
 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





  parent reply	other threads:[~2026-03-19 16:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19 16:33 [PATCH-SERIES ha-manager v2 00/10] include non-HA resources in usage accounting Daniel Kral
2026-03-19 16:33 ` [PATCH ha-manager v2 01/10] rename static node stats to be consistent with similar interfaces Daniel Kral
2026-03-19 16:33 ` [PATCH ha-manager v2 02/10] resources: remove redundant load_config fallback for static config Daniel Kral
2026-03-19 16:33 ` [PATCH ha-manager v2 03/10] remove redundant service_node and migration_target parameter Daniel Kral
2026-03-19 16:33 ` Daniel Kral [this message]
2026-03-19 16:33 ` [PATCH ha-manager v2 05/10] derive static service stats while filling the service stats repository Daniel Kral
2026-03-19 16:33 ` [PATCH ha-manager v2 06/10] test: make static service usage explicit for all resources Daniel Kral
2026-03-19 16:33 ` [PATCH ha-manager v2 07/10] make static service stats indexable by sid Daniel Kral
2026-03-19 16:33 ` [PATCH ha-manager v2 08/10] move static service stats repository to PVE::HA::Usage::Static Daniel Kral
2026-03-19 16:33 ` [PATCH ha-manager v2 09/10] usage: augment service stats with node and state information Daniel Kral
2026-03-19 16:34 ` [PATCH ha-manager v2 10/10] include running non-HA resources in the scheduler's accounting Daniel Kral
2026-03-19 16:56 ` [PATCH-SERIES ha-manager v2 00/10] include non-HA resources in usage accounting Daniel Kral

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=20260319164047.642936-5-d.kral@proxmox.com \
    --to=d.kral@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal