[pve-devel] [PATCH 02/19] add qm migrateexternal
Alexandre Derumier
aderumier at odiso.com
Wed Feb 22 14:33:26 CET 2017
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Qemu.pm | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
PVE/CLI/qm.pm | 2 ++
2 files changed, 86 insertions(+)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 76bba70..01d97bc 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2838,6 +2838,90 @@ __PACKAGE__->register_method({
}});
__PACKAGE__->register_method({
+ name => 'migrate_vm_external',
+ path => '{vmid}/migrate_external',
+ method => 'POST',
+ protected => 1,
+ proxyto => 'node',
+ description => "Migrate virtual machine to external cluster. Creates a new migration task.",
+ permissions => {
+ check => ['perm', '/vms/{vmid}', [ 'VM.Migrate' ]],
+ },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid }),
+ targetip => {
+ type => 'string',
+ description => "Ip address of the target node.",
+ optional => 1,
+ },
+ targetstorage => get_standard_option('pve-storage-id', {
+ description => "remote target storage.",
+ }),
+ migration_type => {
+ type => 'string',
+ enum => ['secure', 'insecure'],
+ description => "Migration traffic is encrypted using an SSH tunnel by default. On secure, completely private networks this can be disabled to increase performance.",
+ optional => 1,
+ },
+ migration_network => {
+ type => 'string', format => 'CIDR',
+ description => "CIDR of the (sub) network that is used for migration.",
+ optional => 1,
+ },
+
+ },
+ },
+ returns => {
+ type => 'string',
+ description => "the task ID.",
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+
+ my $authuser = $rpcenv->get_user();
+
+ PVE::Cluster::check_cfs_quorum();
+
+ my $targetip = extract_param($param, 'targetip');
+
+ my $vmid = extract_param($param, 'vmid');
+
+ raise_param_exc({ migration_vm_external => "Only root can't migrate to a remote cluster." })
+ if $authuser ne 'root at pam';
+
+ $param->{externalcluster} = 1;
+
+
+ # test if VM exists
+ my $conf = PVE::QemuConfig->load_config($vmid);
+
+ # try to detect errors early
+
+ PVE::QemuConfig->check_lock($conf);
+
+ die "can't migrate offline currently" if !PVE::QemuServer::check_running($vmid);
+
+ $param->{online} = 1;
+
+ my $storecfg = PVE::Storage::config();
+
+ die "can't migrate an HA vm to an external cluster" if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha');
+
+ my $realcmd = sub {
+ my $upid = shift;
+
+ PVE::QemuMigrate->migrate($targetip, $targetip, $vmid, $param);
+ };
+
+ return $rpcenv->fork_worker('qmigrate', $vmid, $authuser, $realcmd);
+ }});
+
+__PACKAGE__->register_method({
name => 'monitor',
path => '{vmid}/monitor',
method => 'POST',
diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 44439dd..bdd0656 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -484,6 +484,8 @@ our $cmddef = {
migrate => [ "PVE::API2::Qemu", 'migrate_vm', ['vmid', 'target'], { node => $nodename }, $upid_exit ],
+ migrateexternal => [ "PVE::API2::Qemu", 'migrate_vm_external', ['vmid', 'targetip'], { node => $nodename }, $upid_exit ],
+
set => [ "PVE::API2::Qemu", 'update_vm', ['vmid'], { node => $nodename } ],
resize => [ "PVE::API2::Qemu", 'resize_vm', ['vmid', 'disk', 'size'], { node => $nodename } ],
--
2.1.4
More information about the pve-devel
mailing list