[pve-devel] [PATCH qemu-server v3 2/2] qm rescan: add dryrun option

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Jul 11 08:40:07 CEST 2018


tells an user what would get touched, so he has a chance to fix
unwanted things before changes are actually made.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

* remove one dryrun print, and actually only print the other one in the dryrun
  case

 PVE/CLI/qm.pm     | 12 +++++++++++-
 PVE/QemuServer.pm |  4 ++--
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 48fbc5f..cf26943 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -404,13 +404,23 @@ __PACKAGE__->register_method ({
 		optional => 1,
 		completion => \&PVE::QemuServer::complete_vmid,
 	    }),
+	    dryrun => {
+		type => 'boolean',
+		optional => 1,
+		default => 0,
+		description => 'Do not actually write changes out to conifg.',
+	    },
 	},
     },
     returns => { type => 'null'},
     code => sub {
 	my ($param) = @_;
 
-	PVE::QemuServer::rescan($param->{vmid});
+	my $dryrun = $param->{dryrun};
+
+	print "NOTE: running in dry-run mode, won't write changes out!\n" if $dryrun;
+
+	PVE::QemuServer::rescan($param->{vmid}, 0, $dryrun);
 
 	return undef;
     }});
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index e997049..5e4d0b6 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5606,7 +5606,7 @@ sub update_disksize {
 }
 
 sub rescan {
-    my ($vmid, $nolock) = @_;
+    my ($vmid, $nolock, $dryrun) = @_;
 
     my $cfg = PVE::Storage::config();
 
@@ -5634,7 +5634,7 @@ sub rescan {
 
 	my $changes = update_disksize($vmid, $conf, $vm_volids);
 
-	PVE::QemuConfig->write_config($vmid, $conf) if $changes;
+	PVE::QemuConfig->write_config($vmid, $conf) if $changes && !$dryrun;
     };
 
     if (defined($vmid)) {
-- 
2.18.0





More information about the pve-devel mailing list