From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 80F8F70E46 for ; Wed, 9 Jun 2021 13:54:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7E60323921 for ; Wed, 9 Jun 2021 13:54:21 +0200 (CEST) Received: from kvmformation3.odiso.net (globalOdiso.M6Lille.odiso.net [89.248.211.242]) by firstgate.proxmox.com (Proxmox) with ESMTP id D73F4238DE for ; Wed, 9 Jun 2021 13:54:18 +0200 (CEST) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id 9E257D1B0C; Wed, 9 Jun 2021 13:54:18 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Wed, 9 Jun 2021 13:54:15 +0200 Message-Id: <20210609115417.3326775-6-aderumier@odiso.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210609115417.3326775-1-aderumier@odiso.com> References: <20210609115417.3326775-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.972 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% HEADER_FROM_DIFFERENT_DOMAINS 0.248 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods KHOP_HELO_FCRDNS 0.398 Relay HELO differs from its IP's reverse DNS NO_DNS_FOR_FROM 0.001 Envelope sender has no MX or A DNS records SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [qemu.pm, cloudinit.pm] Subject: [pve-devel] [PATCH v3 qemu-server 5/7] cloudinit : add extract_cloudinit_config X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Jun 2021 11:54:21 -0000 Signed-off-by: Alexandre Derumier --- PVE/API2/Qemu.pm | 1 + PVE/QemuServer/Cloudinit.pm | 47 ++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index cc58744..8ac3ae3 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1063,6 +1063,7 @@ __PACKAGE__->register_method({ path => '{vmid}/cloudinit', method => 'GET', proxyto => 'node', + protected => '1', description => "Get the cloudinit configuration with both current and pending values.", permissions => { check => ['perm', '/vms/{vmid}', [ 'VM.Audit' ]], diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm index 156e073..917511e 100644 --- a/PVE/QemuServer/Cloudinit.pm +++ b/PVE/QemuServer/Cloudinit.pm @@ -607,11 +607,56 @@ sub dump_cloudinit_config { } } +sub extract_cloudinit_config { + my ($conf, $vmid) = @_; + + my $current_drive = undef; + PVE::QemuConfig->foreach_volume($conf, sub { + my ($ds, $drive) = @_; + $current_drive = $drive if PVE::QemuServer::drive_is_cloudinit($drive); + + }); + + my $running = PVE::QemuServer::check_running($vmid); + my $storecfg = PVE::Storage::config(); + my $iso_path = PVE::Storage::path($storecfg, $current_drive->{file}); + my ($storeid, $volname) = PVE::Storage::parse_volume_id($current_drive->{file}, 1); + my $scfg = PVE::Storage::storage_config($storecfg, $storeid); + my $format = PVE::QemuServer::qemu_img_format($scfg, $volname); + my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); + $plugin->activate_volume($storeid, $scfg, $volname) if !$running; + + my $raw_cloudinit_config = undef; + + my $path = "/run/pve/cloudinit_current/$vmid"; + mkpath $path; + my $parser = sub { + my $line = shift; + $raw_cloudinit_config .= "$line\n"; + }; + eval { + #qemu-img dd is really slower (5s) than convert (0.2s) + run_command([ + ['qemu-img', 'convert', '-f', 'raw', '-O', 'raw', "$iso_path", "$path/iso"] + ]); + + run_command([ + ['isoinfo', '-i', "$path/iso", '-x', "/PROXMOX/VMCONF.\;1"] + ], outfunc => $parser); + }; + rmtree($path); + $plugin->deactivate_volume($storeid, $scfg, $volname) if !$running; + + my $cloudinit_config = PVE::QemuServer::parse_vm_config("/qemu-server/$vmid.conf", $raw_cloudinit_config); + return $cloudinit_config; +} + sub get_pending_config { my ($conf, $vmid) = @_; + my $newconf = { %{$conf} }; - my $cloudinit_current = $newconf->{cloudinit}; + my $cloudinit_current = extract_cloudinit_config($conf, $vmid); my @cloudinit_opts = keys %{PVE::QemuServer::cloudinit_config_properties()}; push @cloudinit_opts, 'name'; -- 2.20.1