public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server 6/6] drop get_pending_changes and simplify cloudinit_pending api call
Date: Wed, 16 Nov 2022 18:14:08 +0100	[thread overview]
Message-ID: <20221116171408.216775-7-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20221116171408.216775-1-w.bumiller@proxmox.com>

- The forced-remove flag wasn't really used AFAICT and makes
  no sense IMO.
- Whether or not we care about non-MAC changes does not
  belong here, but should instead taken into account in the
  actual hotplug path recording the cloud-init state (iow.
  into $cloudinit_record_changed().)
  (This is not done here atm.)
- It seems much simpler to just have:
  * 'old' = the old value if it's not a new value
  * 'new' = the new value unless it's being deleted
  * If only one of them is set it's an addition or removal.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
 PVE/API2/Qemu.pm            | 44 +++++++++++----------
 PVE/QemuServer/Cloudinit.pm | 78 -------------------------------------
 2 files changed, 24 insertions(+), 98 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 30348e6..edb495b 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1338,24 +1338,16 @@ __PACKAGE__->register_method({
 		    description => "Configuration option name.",
 		    type => 'string',
 		},
-		value => {
-		    description => "Current value.",
+		old => {
+		    description => "Value as it was used to generate the current cloudinit image.",
 		    type => 'string',
 		    optional => 1,
 		},
-		pending => {
-		    description => "Pending value.",
+		new => {
+		    description => "The new pending value.",
 		    type => 'string',
 		    optional => 1,
 		},
-		delete => {
-		    description => "Indicates a pending delete request if present and not 0. " .
-		                   "The value 2 indicates a force-delete request.",
-		    type => 'integer',
-		    minimum => 0,
-		    maximum => 2,
-		    optional => 1,
-		},
 	    },
 	},
     },
@@ -1365,17 +1357,29 @@ __PACKAGE__->register_method({
 	my $vmid = $param->{vmid};
 	my $conf = PVE::QemuConfig->load_config($vmid);
 
-	if (defined($conf->{cipassword}) &&
-	    defined($conf->{cloudinit}->{cipassword}) &&
-	    $conf->{cipassword} ne $conf->{cloudinit}->{cipassword}) {
-	    $conf->{cipassword} = '********** ';
-	} elsif (defined($conf->{cipassword})) {
-	    $conf->{cipassword} = '**********';
+	my $ci = $conf->{cloudinit};
+
+	my $res = {};
+	my $added = delete($ci->{added}) // '';
+	for my $key (PVE::Tools::split_list($added)) {
+	    $res->{$key} = { new => $conf->{$key} };
 	}
 
-	$conf->{cloudinit}->{cipassword} = '**********' if defined($conf->{cloudinit}->{cipassword});
+	for my $key (keys %$ci) {
+	    if (!exists($conf->{$key})) {
+		$res->{$key} = { old => $ci->{$key} };
+	    } else {
+		$res->{$key} = {
+		    old => $ci->{$key},
+		    new => $conf->{$key},
+		};
+	    }
+	}
 
-	my $res = PVE::QemuServer::Cloudinit::get_pending_config($conf, $vmid);
+	if (defined(my $pw = $res->{cipassword})) {
+	    $pw->{old} = '**********' if exists $pw->{old};
+	    $pw->{new} = '**********' if exists $pw->{new};
+	}
 
 	return $res;
    }});
diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
index 24725e7..a0c3d60 100644
--- a/PVE/QemuServer/Cloudinit.pm
+++ b/PVE/QemuServer/Cloudinit.pm
@@ -627,82 +627,4 @@ sub dump_cloudinit_config {
     }
 }
 
-sub get_pending_config {
-    my ($conf, $vmid) = @_;
-
-    my $newconf = dclone($conf);
-
-    my $cloudinit_current = $newconf->{cloudinit};
-    my @cloudinit_opts = keys %{PVE::QemuServer::cloudinit_config_properties()};
-    push @cloudinit_opts, 'name';
-
-    #add cloud-init drive
-    my $drives = {};
-    PVE::QemuConfig->foreach_volume($newconf, sub {
-	my ($ds, $drive) = @_;
-	$drives->{$ds} = 1 if PVE::QemuServer::drive_is_cloudinit($drive);
-    });
-
-    PVE::QemuConfig->foreach_volume($cloudinit_current, sub {
-	my ($ds, $drive) = @_;
-	$drives->{$ds} = 1 if PVE::QemuServer::drive_is_cloudinit($drive);
-    });
-    for my $ds (keys %{$drives}) {
-	push @cloudinit_opts, $ds;
-    }
-
-    $newconf->{name} = "VM$vmid" if !$newconf->{name};
-    $cloudinit_current->{name} = "VM$vmid" if !$cloudinit_current->{name};
-
-    #only mac-address is used in cloud-init config.
-    #We don't want to display other pending net changes.
-    my $print_cloudinit_net = sub {
-	my ($conf, $opt) = @_;
-
-	if (defined($conf->{$opt})) {
-	    my $net = PVE::QemuServer::parse_net($conf->{$opt});
-	    $conf->{$opt} = "macaddr=".$net->{macaddr} if $net->{macaddr};
-	}
-    };
-
-    my $cloudinit_options = {};
-    for my $opt (@cloudinit_opts) {
-	if ($opt =~ m/^ipconfig(\d+)/) {
-	    my $netid = "net$1";
-
-	    next if !defined($newconf->{$netid}) && !defined($cloudinit_current->{$netid}) &&
-		    !defined($newconf->{$opt}) && !defined($cloudinit_current->{$opt});
-
-	    &$print_cloudinit_net($newconf, $netid);
-	    &$print_cloudinit_net($cloudinit_current, $netid);
-	    $cloudinit_options->{$netid} = 1;
-	}
-	$cloudinit_options->{$opt} = 1;
-    }
-
-    my $res = [];
-
-    for my $opt (keys %{$cloudinit_options}) {
-
-	my $item = {
-	    key => $opt,
-	};
-	if ($cloudinit_current->{$opt}) {
-	    $item->{value} = $cloudinit_current->{$opt};
-	    if (defined($newconf->{$opt})) {
-		$item->{pending} = $newconf->{$opt} 
-		    if $newconf->{$opt} ne $cloudinit_current->{$opt};
-	    } else {
-		$item->{delete} = 1;
-	    }
-	} else {
-	    $item->{pending} = $newconf->{$opt} if $newconf->{$opt}
-	}
-
-	push @$res, $item;
-   }
-
-   return $res;
-}
-
 1;
-- 
2.30.2





  parent reply	other threads:[~2022-11-16 17:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 17:14 [pve-devel] [PATCH qemu-server 0/6] Manage [special:cloudinit] in hotplug code Wolfgang Bumiller
2022-11-16 17:14 ` [pve-devel] [PATCH qemu-server 1/6] Revert "cloudinit: avoid unsafe write of VM config" Wolfgang Bumiller
2022-11-16 17:14 ` [pve-devel] [PATCH qemu-server 2/6] Partially-revert "cloudinit: add cloudinit section for current generated config" Wolfgang Bumiller
2022-11-16 17:14 ` [pve-devel] [PATCH qemu-server 3/6] delay cloudinit generation in hotplug Wolfgang Bumiller
2022-11-16 17:14 ` [pve-devel] [PATCH qemu-server 4/6] record cloud-init changes in the cloudinit section Wolfgang Bumiller
2022-11-16 17:14 ` [pve-devel] [PATCH qemu-server 5/6] don't call 'cleanup_config' " Wolfgang Bumiller
2022-11-16 17:14 ` Wolfgang Bumiller [this message]
2022-11-16 17:41 ` [pve-devel] applied-series: [PATCH qemu-server 0/6] Manage [special:cloudinit] in hotplug code 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=20221116171408.216775-7-w.bumiller@proxmox.com \
    --to=w.bumiller@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal