copy_vm : add optional storage parameter

Optionnal target storage for full copy

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2013-04-30 07:08:27 +02:00 committed by Dietmar Maurer
parent 15b1fc9395
commit 81f043ebc0

View File

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