From: "Michael Köppl" <m.koeppl@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v2 2/2] create_vm: set HA state when restoring VM if resource already exists
Date: Thu, 27 Nov 2025 16:40:41 +0100 [thread overview]
Message-ID: <20251127154041.194423-3-m.koeppl@proxmox.com> (raw)
In-Reply-To: <20251127154041.194423-1-m.koeppl@proxmox.com>
Instead of trying to add a HA resource in any case, which fails if it
already exists and will then not overwrite the status, check if the VM
already is a HA resource. If the resource already exists, set the status
of the existing resource, otherwise add the resource as before.
Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
---
src/PVE/API2/Qemu.pm | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 25b6529c..4d4f0873 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -1417,9 +1417,17 @@ __PACKAGE__->register_method({
}
if ($ha_managed) {
- print "Add as HA resource\n";
+ my $resource_exists = PVE::HA::Config::service_is_configured("vm:$vmid");
my $state = $start_after_create || $live_restore ? 'started' : 'stopped';
- my $cmd = ['ha-manager', 'add', "vm:$vmid", '--state', $state];
+ my $cmd;
+ if ($resource_exists) {
+ print "Update state of HA resource\n";
+ $cmd = ['ha-manager', 'set', "vm:$vmid", '--state', $state];
+ } else {
+ print "Add as HA resource\n";
+ $cmd = ['ha-manager', 'add', "vm:$vmid", '--state', $state];
+ }
+
eval { PVE::Tools::run_command($cmd); };
warn $@ if $@;
}
--
2.47.3
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-11-27 15:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 15:40 [pve-devel] [PATCH qemu-server v2 0/2] correctly set HA state then Michael Köppl
2025-11-27 15:40 ` [pve-devel] [PATCH qemu-server v2 1/2] create_vm: assume HA state 'started' when live-restoring guests Michael Köppl
2025-11-27 15:40 ` Michael Köppl [this message]
2025-11-29 22:49 ` [pve-devel] applied: [PATCH qemu-server v2 0/2] correctly set HA state then Thomas Lamprecht
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=20251127154041.194423-3-m.koeppl@proxmox.com \
--to=m.koeppl@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.