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 <[email protected]>
---
 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
[email protected]
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to