[pve-devel] [PATCH qemu-server 1/1] api: create/store: allow adding VM as HA resource after creation
Daniel Kral
d.kral at proxmox.com
Mon Nov 10 13:30:19 CET 2025
On Mon Oct 6, 2025 at 5:52 PM CEST, Michael Köppl wrote:
> @@ -1204,6 +1210,7 @@ __PACKAGE__->register_method({
> my $force = extract_param($param, 'force');
> my $pool = extract_param($param, 'pool');
> my $start_after_create = extract_param($param, 'start');
> + my $ha_managed = extract_param($param, 'ha-managed');
> my $storage = extract_param($param, 'storage');
> my $unique = extract_param($param, 'unique');
> my $live_restore = extract_param($param, 'live-restore');
> @@ -1380,6 +1387,15 @@ __PACKAGE__->register_method({
> eval { PVE::API2::Qemu->vm_start({ vmid => $vmid, node => $node }) };
> warn $@ if $@;
> }
> +
> + if ($ha_managed) {
> + print "Add as HA resource\n";
> + my $state = $start_after_create ? 'started' : 'stopped';
> + eval {
> + PVE::API2::HA::Resources->create({ sid => "vm:$vmid", state => $state });
> + };
> + warn $@ if $@;
> + }
Was there a reason that in the restore function the VM is added to the
HA stack after the vm_start(...) / live restore while in the create
function it is added before vm_start(...) / live import?
I just wonder if it might cause any trouble with these :)
> };
>
> my $createfn = sub {
> @@ -1463,6 +1479,15 @@ __PACKAGE__->register_method({
>
> PVE::QemuConfig->lock_config_full($vmid, 1, $realcmd);
>
> + if ($ha_managed) {
> + print "Add as HA resource\n";
> + my $state = $start_after_create ? 'started' : 'stopped';
> + eval {
> + PVE::API2::HA::Resources->create({ sid => "vm:$vmid", state => $state });
> + };
> + warn $@ if $@;
> + }
> +
> if ($start_after_create && !$live_restore) {
> print "Execute autostart\n";
> eval { PVE::API2::Qemu->vm_start({ vmid => $vmid, node => $node }) };
More information about the pve-devel
mailing list