From: "Michael Köppl" <m.koeppl@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH container 1/1] api: create/store: allow adding CT as HA resource after creation
Date: Mon, 6 Oct 2025 17:52:30 +0200 [thread overview]
Message-ID: <20251006155233.267374-3-m.koeppl@proxmox.com> (raw)
In-Reply-To: <20251006155233.267374-1-m.koeppl@proxmox.com>
Extend the creation and restore actions with a 'ha-managed' parameter
that, if enabled, will also add the CT as a new HA resource. The 'state'
parameter for this new resource will match the value of the 'start'
parameter used during creation of the CT, such that the resulting state
of the resource and CT both match the user's expectation (avoid
situation where user creates a CT, does not select 'Start after
creation', but the default 'started' state of the resource would start
the CT anyway).
Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
---
src/PVE/API2/LXC.pm | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 37b9d055..e53b388d 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -218,6 +218,12 @@ __PACKAGE__->register_method({
default => 0,
description => "Start the CT after its creation finished successfully.",
},
+ 'ha-managed' => {
+ optional => 1,
+ type => 'boolean',
+ default => 0,
+ description => "Add the CT as a HA resource after it was created.",
+ },
}),
},
returns => {
@@ -236,6 +242,7 @@ __PACKAGE__->register_method({
my $ignore_unpack_errors = extract_param($param, 'ignore-unpack-errors');
my $bwlimit = extract_param($param, 'bwlimit');
my $start_after_create = extract_param($param, 'start');
+ my $ha_managed = extract_param($param, 'ha-managed');
my $basecfg_fn = PVE::LXC::Config->config_file($vmid);
my $same_container_exists = -f $basecfg_fn;
@@ -616,6 +623,15 @@ __PACKAGE__->register_method({
} elsif ($start_after_create) {
PVE::API2::LXC::Status->vm_start({ vmid => $vmid, node => $node });
}
+
+ if ($ha_managed) {
+ print "Add as HA resource\n";
+ my $state = $start_after_create ? 'started' : 'stopped';
+ eval {
+ PVE::API2::HA::Resources->create({ sid => "ct:$vmid", state => $state });
+ };
+ warn $@ if $@;
+ }
};
return $rpcenv->fork_worker($workername, $vmid, $authuser, $realcmd);
--
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-10-06 15:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 15:52 [pve-devel] [PATCH container/manager/qemu-server 0/5] add option to create HA resource upon guest create or restore Michael Köppl
2025-10-06 15:52 ` [pve-devel] [PATCH qemu-server 1/1] api: create/store: allow adding VM as HA resource after creation Michael Köppl
2025-10-06 17:23 ` Thomas Lamprecht
2025-10-06 17:24 ` Thomas Lamprecht
2025-10-06 15:52 ` Michael Köppl [this message]
2025-10-06 17:22 ` [pve-devel] applied: [PATCH container 1/1] api: create/store: allow adding CT " Thomas Lamprecht
2025-10-06 15:52 ` [pve-devel] [PATCH manager 1/3] qemu: create: add checkbox for creating HA resource upon VM creation Michael Köppl
2025-10-06 17:29 ` Thomas Lamprecht
2025-10-07 9:52 ` Michael Köppl
2025-10-07 10:26 ` Thomas Lamprecht
2025-10-07 11:46 ` Michael Köppl
2025-10-07 12:42 ` Michael Köppl
2025-10-06 15:52 ` [pve-devel] [PATCH manager 2/3] lxc: create: add checkbox for creating HA resource upon CT creation Michael Köppl
2025-10-06 15:52 ` [pve-devel] [PATCH manager 3/3] ui: restore: add checkbox for adding HA resource upon restore of guest Michael Köppl
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=20251006155233.267374-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.