[pve-devel] [PATCH common 4/4] use the pvecm mtunnel command to get remote migration ip

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Oct 27 17:00:18 CEST 2016


Ask the pvecm mtunnel command (was earlier in qm) if the remote side
has an IP configured in a given migration_network denoted by a CIDR.

If such a IP is available reset the nodeip and rem_ssh variables
and check if we can connect to the other side with ssh public key
authentication.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 src/PVE/AbstractMigrate.pm | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/PVE/AbstractMigrate.pm b/src/PVE/AbstractMigrate.pm
index 00d0ff5..9f3d233 100644
--- a/src/PVE/AbstractMigrate.pm
+++ b/src/PVE/AbstractMigrate.pm
@@ -82,6 +82,28 @@ sub cmd_logerr {
     return &$run_command_quiet_full($self, $cmd, 1, %param);
 }
 
+sub get_remote_migration_ip {
+    my ($self) = @_;
+
+    my $ip;
+
+    my $cmd = [@{$self->{rem_ssh}}, 'pvecm', 'mtunnel', '--get_migration_ip'];
+
+    push @$cmd, '--migration_network', $self->{opts}->{migration_network}
+      if defined($self->{opts}->{migration_network});
+
+    PVE::Tools::run_command($cmd, outfunc => sub {
+	my $line = shift;
+
+	# use non-restrictive regex for ip, its already checked by the remote side
+	if ($line =~ m/^ip: '(\S+)'$/) {
+	   $ip = $1;
+	}
+    });
+
+    return $ip;
+}
+
 sub test_remote_ssh_connection {
     my ($self) = @_;
 
@@ -157,6 +179,18 @@ sub migrate {
 
 	$self->test_remote_ssh_connection();
 
+	# get dedicated migration address from remote node if set
+	if (my $remote_migration_ip = $self->get_remote_migration_ip()) {
+	    $nodeip = $remote_migration_ip;
+	    $self->{nodeip} = $remote_migration_ip;
+	    $self->{rem_ssh} = [ @ssh_cmd, "root\@$nodeip" ];
+
+	    $self->log('info', "use dedicated network address for sending " .
+	               "migration traffic ($self->{nodeip})");
+	    # test again with new IP
+	    $self->test_remote_ssh_connection();
+	}
+
 	&$eval_int($self, sub { $self->phase1($self->{vmid}); });
 	my $err = $@;
 	if ($err) {
-- 
2.1.4





More information about the pve-devel mailing list