[pve-devel] [PATCH pve-container 8/9] add move_disk function to API
Wolfgang Link
w.link at proxmox.com
Wed Nov 18 09:30:05 CET 2015
---
src/PVE/API2/LXC.pm | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/PVE/CLI/pct.pm | 2 ++
src/PVE/LXC.pm | 4 +--
3 files changed, 91 insertions(+), 2 deletions(-)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 165e327..dbf4057 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1092,4 +1092,91 @@ __PACKAGE__->register_method({
return PVE::LXC::lock_container($vmid, undef, $code);;
}});
+__PACKAGE__->register_method({
+ name => 'move_lxc_disk',
+ path => '{vmid}/move_disk',
+ method => 'POST',
+ protected => 1,
+ proxyto => 'node',
+ description => "Move volume to different storage.",
+ permissions => {
+ description => "You need 'VM.Config.Disk' permissions on /vms/{vmid}, " .
+ "and 'Datastore.AllocateSpace' permissions on the storage.",
+ check =>
+ [ 'and',
+ ['perm', '/vms/{vmid}', [ 'VM.Config.Disk' ]],
+ ['perm', '/storage/{storage}', [ 'Datastore.AllocateSpace' ]],
+ ],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid }),
+ disk => {
+ type => 'string',
+ description => "The disk you want to move.",
+ completion => \&PVE::LXC::complete_disk,
+ },
+ storage => get_standard_option('pve-storage-id', {
+ description => "Target storage.",
+ completion => \&PVE::LXC::complete_storage,
+ }),
+ 'format' => {
+ type => 'string',
+ description => "Target Format.",
+ enum => [ 'raw', 'subvol' ],
+ optional => 1,
+ },
+ delete => {
+ type => 'boolean',
+ description => "Delete the original disk after successful copy. By default the original disk is kept as unused disk.",
+ optional => 1,
+ enum => [ 1, 0 ],
+ default => 0,
+ },
+ digest => {
+ type => 'string',
+ description => 'Prevent changes if current configuration file has different SHA1 digest. This can be used to prevent concurrent modifications.',
+ maxLength => 40,
+ optional => 1,
+ },
+ },
+ },
+ returns => {
+ type => 'string',
+ description => "the task ID.",
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+
+ my $authuser = $rpcenv->get_user();
+
+ my $node = extract_param($param, 'node');
+
+ my $vmid = extract_param($param, 'vmid');
+
+ my $digest = extract_param($param, 'digest');
+
+ my $disk = extract_param($param, 'disk');
+
+ my $storeid = extract_param($param, 'storage');
+
+ my $format = extract_param($param, 'format');
+
+ my $storecfg = PVE::Storage::config();
+
+ die "Storage do not support container\n" if !$storeid;
+
+ my $updatefn = sub {
+
+ print "Not implemented now!!";
+
+ };
+
+ return PVE::LXC::lock_container($vmid, undef, $updatefn);
+ }});
+
1;
diff --git a/src/PVE/CLI/pct.pm b/src/PVE/CLI/pct.pm
index 80205bb..c802fe9 100755
--- a/src/PVE/CLI/pct.pm
+++ b/src/PVE/CLI/pct.pm
@@ -266,6 +266,8 @@ our $cmddef = {
rollback => [ "PVE::API2::LXC::Snapshot", 'rollback', ['vmid', 'snapname'], { node => $nodename } , $upid_exit ],
template => [ "PVE::API2::LXC", 'template', ['vmid'], { node => $nodename }],
+
+ move_disk => [ "PVE::API2::LXC", 'move_lxc_disk', ['vmid', 'disk', 'storage'], { node => $nodename }, $upid_exit ],
};
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 66fb278..b8db150 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2157,7 +2157,7 @@ sub rsync_disk {
}
sub copy_lxc_disk {
- my ($src_volid, $dst_volid, $storecfg);
+ my ($src_volid, $dst_volid, $storecfg) = @_;
my (undef, undef, $src_vmid, undef, undef, undef, $src_format) =
PVE::Storage::parse_volname($storecfg, $src_volid);
@@ -2167,7 +2167,7 @@ sub copy_lxc_disk {
my $running = check_running($src_vmid);
- my $snapable = volume_has_feature($storecfg, 'snapshot', $src_volid, undef, 1);
+ my $snapable = PVE::Storage::volume_has_feature($storecfg, 'snapshot', $src_volid, undef, 1);
die "Can't copy Disk: $src_volid to $dst_volid, if it is running" if
($running && $src_vmid == $dst_vmid && $snapable);
--
2.1.4
More information about the pve-devel
mailing list