From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC qemu-server] api: create disks: avoid adding secondary cloud-init drives
Date: Fri, 6 May 2022 12:11:14 +0200 [thread overview]
Message-ID: <20220506101114.45522-1-f.ebner@proxmox.com> (raw)
This will break possibly existing workflows like
1. add second cloud-init
2. remove first cloud-init
to change the cloud-init storage.
On the other hand, it avoids unintended misconfiguration of having
mutliple cloud-init drives with potentially different settings.
Also in preparation for adding cloud-init-related API calls, where
not being able to assume that there's only one cloud-init drive/state
would complicate things quite a bit.
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
Are there any scenarios where having multiple cloud-init drives is
useful?
PVE/API2/Qemu.pm | 19 +++++++++++++++++++
PVE/QemuConfig.pm | 15 +++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index a8246574..74f0181c 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -328,6 +328,15 @@ my $create_disks = sub {
} elsif (defined($volname) && $volname eq 'cloudinit') {
$storeid = $storeid // $default_storage;
die "no storage ID specified (and no default storage)\n" if !$storeid;
+
+ if (
+ my $ci_key = PVE::QemuConfig->has_cloudinit($conf, $ds)
+ || PVE::QemuConfig->has_cloudinit($conf->{pending} || {}, $ds)
+ || PVE::QemuConfig->has_cloudinit($res, $ds)
+ ) {
+ die "$ds - cloud-init drive is already attached at '$ci_key'\n";
+ }
+
my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
my $name = "vm-$vmid-cloudinit";
@@ -424,6 +433,16 @@ my $create_disks = sub {
my ($vtype) = PVE::Storage::parse_volname($storecfg, $volid);
die "cannot use volume $volid - content type needs to be 'images' or 'iso'"
if $vtype ne 'images' && $vtype ne 'iso';
+
+ if (PVE::QemuServer::Drive::drive_is_cloudinit($disk)) {
+ if (
+ my $ci_key = PVE::QemuConfig->has_cloudinit($conf, $ds)
+ || PVE::QemuConfig->has_cloudinit($conf->{pending} || {}, $ds)
+ || PVE::QemuConfig->has_cloudinit($res, $ds)
+ ) {
+ die "$ds - cloud-init drive is already attached at '$ci_key'\n";
+ }
+ }
}
PVE::Storage::activate_volumes($storecfg, [ $volid ]) if $storeid;
diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index cfef8d37..f7557613 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -518,4 +518,19 @@ sub __snapshot_rollback_get_unused {
# END implemented abstract methods from PVE::AbstractConfig
+sub has_cloudinit {
+ my ($class, $conf, $skip) = @_;
+
+ my $found;
+
+ $class->foreach_volume($conf, sub {
+ my ($key, $volume) = @_;
+
+ return if ($skip && $skip eq $key) || $found;
+ $found = $key if PVE::QemuServer::Drive::drive_is_cloudinit($volume);
+ });
+
+ return $found;
+}
+
1;
--
2.30.2
next reply other threads:[~2022-05-06 10:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-06 10:11 Fabian Ebner [this message]
2022-05-16 8:32 ` DERUMIER, Alexandre
2022-07-04 8:54 ` Mira Limbeck
2022-05-16 11:04 ` DERUMIER, Alexandre
2022-07-04 8:57 ` Mira Limbeck
2022-07-04 7:44 ` Fabian Ebner
2022-09-12 16:06 ` [pve-devel] applied: " 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=20220506101114.45522-1-f.ebner@proxmox.com \
--to=f.ebner@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal