[pve-devel] [PATCH qemu-server 2/2] Add new qm option 'diskimport' to import external disk images

Emmanuel Kasper e.kasper at proxmox.com
Tue Apr 25 10:56:02 CEST 2017


The VM must be already existing, and the synthax is
qm diskimport 421 -source minix204.img -storage pve4tank

where 421 is an already existing VM
---
 PVE/CLI/qm.pm | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 44439dd..e52ebac 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -17,6 +17,7 @@ use PVE::SafeSyslog;
 use PVE::INotify;
 use PVE::RPCEnvironment;
 use PVE::QemuServer;
+use PVE::QemuServer::DiskImport;
 use PVE::API2::Qemu;
 use JSON;
 use PVE::JSONSchema qw(get_standard_option);
@@ -380,6 +381,42 @@ __PACKAGE__->register_method ({
     }});
 
 __PACKAGE__->register_method ({
+    name => 'diskimport',
+    path => 'diskimport',
+    method => 'POST',
+    description => "Import an external disk image as an unused disk in a VM. The disk
+ format is automatically detected by qemu-img(1).",
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    vmid => get_standard_option('pve-vmid', {completion => \&PVE::QemuServer::complete_vmid}),
+	    source => {
+		description => "path to the disk image to import",
+		type => "string",
+		optional => 0},
+	    storage => {
+		description => "the storage identifier",
+		type => "string",
+		completion => \&PVE::Storage::complete_storage_enabled,
+		optional => 0},
+	},
+    },
+    returns => { type => 'null'},
+    code => sub {
+	my ($params) = @_;
+	my $vmid = $params->{vmid};
+
+	PVE::QemuServer::DiskImport::do_import({
+	    src_path => $params->{source},
+	    vmid => $params->{vmid},
+	    storage_id => $params->{storage},
+	    disk_entry => undef, # add as unused disk
+	    debug => 0
+	});
+	return undef;
+    }});
+
+__PACKAGE__->register_method ({
     name => 'terminal',
     path => 'terminal',
     method => 'POST',
@@ -587,6 +624,8 @@ our $cmddef = {
     nbdstop => [ __PACKAGE__, 'nbdstop', ['vmid']],
 
     terminal => [ __PACKAGE__, 'terminal', ['vmid']],
+
+    diskimport => [ __PACKAGE__, 'diskimport', ['vmid']],
 };
 
 1;
-- 
2.11.0





More information about the pve-devel mailing list