[pve-devel] [PATCH 02/19] add qm migrateexternal

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Mar 9 12:31:30 CET 2017


The order of this patch is a bit strange to me, at this point the patch
cannot work, it needs the other one later in this series, or am I mistaken?
I'd try to introduce this only at the point where it can (minimally) work
with the previous patches.

some other small comments inline, but looks ok in generak, I need to look at
the other stuff first to get thewhole picture :)

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.",
+            }),

nit picking: Both parameters above should get underscores to separate the
words, enhances readability and thus maintainability of the code, i.e.

target_ip and target_storage respectively.

+        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." })

Typo here, s/can't/can/

+            if $authuser ne 'root at pam';
+
+    $param->{externalcluster} = 1;
+

Same here, external_cluster or maybe better, external_migration (as the 
target can
also be a single node PVE, I guess).

+
+    # 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');
+

The last part of the check is here not desired:
  && $rpcenv->{type} ne 'ha'

We do not want to migrate away HA VMs to another cluster, for now, as the HA
stack is not tested to cope with it.


+    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