[pve-devel] [PATCH] copy_vm : add optional storage parameter

Alexandre Derumier aderumier at odiso.com
Tue Apr 30 07:08:27 CEST 2013


Optionnal target storage for full copy

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 8a15abc..0fe0045 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -60,7 +60,7 @@ my $check_storage_access = sub {
 };
 
 my $check_storage_access_copy = sub {
-   my ($rpcenv, $authuser, $storecfg, $conf) = @_;
+   my ($rpcenv, $authuser, $storecfg, $conf, $storage) = @_;
 
    PVE::QemuServer::foreach_drive($conf, sub {
 	my ($ds, $drive) = @_;
@@ -80,6 +80,7 @@ my $check_storage_access_copy = sub {
 	} else {
 	    my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
 	    die "unable to copy arbitrary files\n" if !$sid;
+	    $sid = $storage if $storage;
 	    $rpcenv->check($authuser, "/storage/$sid", ['Datastore.AllocateSpace']);
 	}
     });
@@ -1806,6 +1807,10 @@ __PACKAGE__->register_method({
 		type => 'string', format => 'pve-poolid',
 		description => "Add the new VM to the specified pool.",
 	    },
+	    storage => get_standard_option('pve-storage-id', {
+		description => "Target storage for full copy.",
+		optional => 1,
+	    }),
 	    full => {
 		optional => 1,
 		type => 'boolean',
@@ -1838,6 +1843,8 @@ __PACKAGE__->register_method({
 	    $rpcenv->check_pool_exist($pool);
 	}
 
+	my $storage = extract_param($param, 'storage');
+
 	my $storecfg = PVE::Storage::config();
 
 	PVE::Cluster::check_cfs_quorum();
@@ -1857,7 +1864,7 @@ __PACKAGE__->register_method({
 
 	    die "Copy running VM $vmid not implemented\n" if $running;
 
-	    &$check_storage_access_copy($rpcenv, $authuser, $storecfg, $conf);
+	    &$check_storage_access_copy($rpcenv, $authuser, $storecfg, $conf, $storage);
 
 	    # fixme: snapshots??
 
@@ -1917,6 +1924,7 @@ __PACKAGE__->register_method({
 				$newvolid = PVE::Storage::vdisk_clone($storecfg,  $drive->{file}, $newid);
 			    } else {
 				my ($storeid, $volname) = PVE::Storage::parse_volume_id($drive->{file});
+				$storeid = $storage if $storage;
 				my $defformat = PVE::Storage::storage_default_format($storecfg, $storeid);
 				my $fmt = $drive->{format} || $defformat;
 
-- 
1.7.10.4




More information about the pve-devel mailing list