all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH ha-manager] resources: assert ha resource has correct guest type
@ 2026-01-12 10:16 Daniel Kral
  2026-01-12 16:24 ` Michael Köppl
  2026-01-13 13:42 ` [pve-devel] applied: " Fiona Ebner
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Kral @ 2026-01-12 10:16 UTC (permalink / raw)
  To: pve-devel

Otherwise a HA resource with the wrong guest type can be added to the HA
resources configuration, which will make its methods (start, shutdown,
migrate, ...) fail.

This does not fixup existing HA resource entries with the wrong guest
type, but manual removal, e.g., through `ha-manager remove <sid>` and
re-adding it correctly, is still possible.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
---
 src/PVE/HA/Resources/PVECT.pm | 12 +++++++++---
 src/PVE/HA/Resources/PVEVM.pm | 12 +++++++++---
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/PVE/HA/Resources/PVECT.pm b/src/PVE/HA/Resources/PVECT.pm
index 091249d7..55f0373b 100644
--- a/src/PVE/HA/Resources/PVECT.pm
+++ b/src/PVE/HA/Resources/PVECT.pm
@@ -53,13 +53,19 @@ sub exists {
     my ($class, $vmid, $noerr) = @_;
 
     my $vmlist = PVE::Cluster::get_vmlist();
+    my $entry = $vmlist->{ids}->{$vmid};
 
-    if (!defined($vmlist->{ids}->{$vmid})) {
+    if (!defined($entry)) {
         die "resource 'ct:$vmid' does not exist in cluster\n" if !$noerr;
         return undef;
-    } else {
-        return 1;
     }
+
+    if ($entry->{type} ne 'lxc') {
+        die "resource 'ct:$vmid' is not a container\n" if !$noerr;
+        return undef;
+    }
+
+    return 1;
 }
 
 sub start {
diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
index d1bc3329..3664837b 100644
--- a/src/PVE/HA/Resources/PVEVM.pm
+++ b/src/PVE/HA/Resources/PVEVM.pm
@@ -53,13 +53,19 @@ sub exists {
     my ($class, $vmid, $noerr) = @_;
 
     my $vmlist = PVE::Cluster::get_vmlist();
+    my $entry = $vmlist->{ids}->{$vmid};
 
-    if (!defined($vmlist->{ids}->{$vmid})) {
+    if (!defined($entry)) {
         die "resource 'vm:$vmid' does not exist in cluster\n" if !$noerr;
         return undef;
-    } else {
-        return 1;
     }
+
+    if ($entry->{type} ne 'qemu') {
+        die "resource 'vm:$vmid' is not a VM\n" if !$noerr;
+        return undef;
+    }
+
+    return 1;
 }
 
 sub start {
-- 
2.47.3



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH ha-manager] resources: assert ha resource has correct guest type
  2026-01-12 10:16 [pve-devel] [PATCH ha-manager] resources: assert ha resource has correct guest type Daniel Kral
@ 2026-01-12 16:24 ` Michael Köppl
  2026-01-13 13:42 ` [pve-devel] applied: " Fiona Ebner
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Köppl @ 2026-01-12 16:24 UTC (permalink / raw)
  To: Proxmox VE development discussion; +Cc: pve-devel

Gave this a quick spin by running `ha-manager add ct:101` for a VM with
VMID 101 and `ha-manager add vm:102` for a container with VMID 102.
Works as advertised, the error message is informative enough and is
definitely preferrable to constantly failing tasks from HA. The case
with `ha-manager add ct:101 --type vm` is already covered, but this
covers the case that I think is easier to miss.

The code changes themselves look simple enough and lgtm!

Consider this:
Tested-by: Michael Köppl <m.koeppl@proxmox.com>
Reviewed-by: Michael Köppl <m.koeppl@proxmox.com>

On Mon Jan 12, 2026 at 11:16 AM CET, Daniel Kral wrote:
> Otherwise a HA resource with the wrong guest type can be added to the HA
> resources configuration, which will make its methods (start, shutdown,
> migrate, ...) fail.
>
> This does not fixup existing HA resource entries with the wrong guest
> type, but manual removal, e.g., through `ha-manager remove <sid>` and
> re-adding it correctly, is still possible.
>
> Signed-off-by: Daniel Kral <d.kral@proxmox.com>
> ---
>  src/PVE/HA/Resources/PVECT.pm | 12 +++++++++---
>  src/PVE/HA/Resources/PVEVM.pm | 12 +++++++++---
>  2 files changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/src/PVE/HA/Resources/PVECT.pm b/src/PVE/HA/Resources/PVECT.pm
> index 091249d7..55f0373b 100644
> --- a/src/PVE/HA/Resources/PVECT.pm
> +++ b/src/PVE/HA/Resources/PVECT.pm
> @@ -53,13 +53,19 @@ sub exists {
>      my ($class, $vmid, $noerr) = @_;
>  
>      my $vmlist = PVE::Cluster::get_vmlist();
> +    my $entry = $vmlist->{ids}->{$vmid};
>  
> -    if (!defined($vmlist->{ids}->{$vmid})) {
> +    if (!defined($entry)) {
>          die "resource 'ct:$vmid' does not exist in cluster\n" if !$noerr;
>          return undef;
> -    } else {
> -        return 1;
>      }
> +
> +    if ($entry->{type} ne 'lxc') {
> +        die "resource 'ct:$vmid' is not a container\n" if !$noerr;
> +        return undef;
> +    }
> +
> +    return 1;
>  }
>  
>  sub start {
> diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
> index d1bc3329..3664837b 100644
> --- a/src/PVE/HA/Resources/PVEVM.pm
> +++ b/src/PVE/HA/Resources/PVEVM.pm
> @@ -53,13 +53,19 @@ sub exists {
>      my ($class, $vmid, $noerr) = @_;
>  
>      my $vmlist = PVE::Cluster::get_vmlist();
> +    my $entry = $vmlist->{ids}->{$vmid};
>  
> -    if (!defined($vmlist->{ids}->{$vmid})) {
> +    if (!defined($entry)) {
>          die "resource 'vm:$vmid' does not exist in cluster\n" if !$noerr;
>          return undef;
> -    } else {
> -        return 1;
>      }
> +
> +    if ($entry->{type} ne 'qemu') {
> +        die "resource 'vm:$vmid' is not a VM\n" if !$noerr;
> +        return undef;
> +    }
> +
> +    return 1;
>  }
>  
>  sub start {



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] applied: [PATCH ha-manager] resources: assert ha resource has correct guest type
  2026-01-12 10:16 [pve-devel] [PATCH ha-manager] resources: assert ha resource has correct guest type Daniel Kral
  2026-01-12 16:24 ` Michael Köppl
@ 2026-01-13 13:42 ` Fiona Ebner
  1 sibling, 0 replies; 3+ messages in thread
From: Fiona Ebner @ 2026-01-13 13:42 UTC (permalink / raw)
  To: pve-devel, Daniel Kral

On Mon, 12 Jan 2026 11:16:49 +0100, Daniel Kral wrote:
> Otherwise a HA resource with the wrong guest type can be added to the HA
> resources configuration, which will make its methods (start, shutdown,
> migrate, ...) fail.
> 
> This does not fixup existing HA resource entries with the wrong guest
> type, but manual removal, e.g., through `ha-manager remove <sid>` and
> re-adding it correctly, is still possible.
> 
> [...]

Applied with Michael's R-b and T-b, thanks! I slightly changed the
error message to
resource 'ct:$vmid' - guest with ID $vmid is not a container
just to avoid any potential for confusion (stating "ct:something is
not a ct" can sound a bit off).

[1/1] resources: assert ha resource has correct guest type
      commit: 18b3b0950c04a8aaeb1b6a406a13f437ac6e7792


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-13 13:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-12 10:16 [pve-devel] [PATCH ha-manager] resources: assert ha resource has correct guest type Daniel Kral
2026-01-12 16:24 ` Michael Köppl
2026-01-13 13:42 ` [pve-devel] applied: " Fiona Ebner

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