public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v3 qemu-server 2/3] api: create: allow overriding non-disk options during restore
Date: Tue, 26 Apr 2022 14:30:51 +0200	[thread overview]
Message-ID: <20220426123055.110358-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20220426123055.110358-1-f.ebner@proxmox.com>

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

No changes from v2.

 PVE/API2/Qemu.pm  |  8 ++++++--
 PVE/QemuServer.pm | 26 ++++++++++++++++++++------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 61aee0ba..54af11a0 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -819,8 +819,11 @@ __PACKAGE__->register_method({
 	}
 
 	if ($archive) {
-	    my $keystr = join(' ', keys %$param);
-	    raise_param_exc({ archive => "option conflicts with other options ($keystr)"}) if $keystr;
+	    for my $opt (sort keys $param->%*) {
+		if (PVE::QemuServer::Drive::is_valid_drivename($opt)) {
+		    raise_param_exc({ $opt => "option conflicts with option 'archive'" });
+		}
+	    }
 
 	    if ($archive eq '-') {
 		die "pipe requires cli environment\n" if $rpcenv->{type} ne 'cli';
@@ -876,6 +879,7 @@ __PACKAGE__->register_method({
 		    unique => $unique,
 		    bwlimit => $bwlimit,
 		    live => $live_restore,
+		    override_conf => $param,
 		};
 		if ($archive->{type} eq 'file' || $archive->{type} eq 'pipe') {
 		    die "live-restore is only compatible with backup images from a Proxmox Backup Server\n"
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 5db10fe6..2a3e6d58 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -6480,6 +6480,17 @@ my $restore_destroy_volumes = sub {
     }
 };
 
+my $restore_merge_config = sub {
+    my ($filename, $backup_conf_raw, $override_conf) = @_;
+
+    my $backup_conf = parse_vm_config($filename, $backup_conf_raw);
+    for my $key (keys $override_conf->%*) {
+	$backup_conf->{$key} = $override_conf->{$key};
+    }
+
+    return $backup_conf;
+};
+
 sub scan_volids {
     my ($cfg, $vmid) = @_;
 
@@ -6789,9 +6800,8 @@ sub restore_proxmox_backup_archive {
 	$new_conf_raw .= "\nlock: create";
     }
 
-    PVE::Tools::file_set_contents($conffile, $new_conf_raw);
-
-    PVE::Cluster::cfs_update(); # make sure we read new file
+    my $new_conf = $restore_merge_config->($conffile, $new_conf_raw, $options->{override_conf});
+    PVE::QemuConfig->write_config($vmid, $new_conf);
 
     eval { rescan($vmid, 1); };
     warn $@ if $@;
@@ -7095,9 +7105,8 @@ sub restore_vma_archive {
 	die $err;
     }
 
-    PVE::Tools::file_set_contents($conffile, $new_conf_raw);
-
-    PVE::Cluster::cfs_update(); # make sure we read new file
+    my $new_conf = $restore_merge_config->($conffile, $new_conf_raw, $opts->{override_conf});
+    PVE::QemuConfig->write_config($vmid, $new_conf);
 
     eval { rescan($vmid, 1); };
     warn $@ if $@;
@@ -7108,6 +7117,11 @@ sub restore_vma_archive {
 sub restore_tar_archive {
     my ($archive, $vmid, $user, $opts) = @_;
 
+    if (scalar(keys $opts->{override_conf}->%*) > 0) {
+	my $keystring = join(' ', keys $opts->{override_conf}->%*);
+	die "cannot pass along options ($keystring) when restoring from tar archive\n";
+    }
+
     if ($archive ne '-') {
 	my $firstfile = tar_archive_read_firstfile($archive);
 	die "ERROR: file '$archive' does not look like a QemuServer vzdump backup\n"
-- 
2.30.2





  parent reply	other threads:[~2022-04-26 12:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26 12:30 [pve-devel] [PATCH-SERIES v3 qemu-server/manager] more flexible restore Fabian Ebner
2022-04-26 12:30 ` [pve-devel] [PATCH v3 qemu-server 1/3] api: create: refactor parameter check logic Fabian Ebner
2022-04-28  9:12   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-26 12:30 ` Fabian Ebner [this message]
2022-04-28  9:12   ` [pve-devel] applied: [PATCH v3 qemu-server 2/3] api: create: allow overriding non-disk options during restore Thomas Lamprecht
2022-04-26 12:30 ` [pve-devel] [PATCH v3 qemu-server 3/3] restore: allow specifying drive actions " Fabian Ebner
2022-04-26 12:30 ` [pve-devel] [PATCH v3 manager 1/3] ui: restore: disallow empty storage selection if it wouldn't work Fabian Ebner
2022-04-28  9:13   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-26 12:30 ` [pve-devel] [PATCH v3 manager 2/3] ui: restore: allow override of some settings Fabian Ebner
2022-04-28  9:13   ` [pve-devel] applied: " Thomas Lamprecht
2022-04-26 12:30 ` [pve-devel] [PATCH v3 manager 3/3] ui: restore: allow treating disks differently Fabian Ebner

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=20220426123055.110358-3-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 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