From b634bf3a0b3dbccec6c3d7b26ab2a67d8eb1a6e5 Mon Sep 17 00:00:00 2001 From: Bob Ball Date: Wed, 16 Apr 2014 13:23:45 +0100 Subject: [PATCH] XenAPI: Use local rsync rather than remote if possible Using ssh depends on the host being set up to be able to SSH into itself which is not a common scenario. While this is unavoidable for the current implementation of resize across multiple hosts, if there is a single host (i.e. a test scenario) or the resize is restricted to the same host then we can succeed without SSH access Dependency on Ia310e31d31aaf5c979e41c64af8223202a18e03a is because the tests will always fail without Ia310 therefore this fix cannot be tested without taking Ia310 as well. Closes-bug: 1308064 Change-Id: I15802a1d97d380b1c5b74fc9f92ece2494fe789a --- .../xenapi/etc/xapi.d/plugins/migration | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration index bf5af304a9..4ffa9d3a00 100755 --- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration +++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration @@ -36,15 +36,21 @@ def move_vhds_into_sr(session, instance_uuid, sr_path, uuid_stack): def _rsync_vhds(instance_uuid, host, staging_path, user="root"): - ssh_cmd = 'ssh -o StrictHostKeyChecking=no' - if not staging_path.endswith('/'): staging_path += '/' - dest_path = '%s@%s:/images/instance%s/' % (user, host, instance_uuid) + dest_path = '/images/instance%s/' % (instance_uuid) - rsync_cmd = ["/usr/bin/rsync", "-av", "--progress", "-e", ssh_cmd, - staging_path, dest_path] + ip_cmd = ["/sbin/ip", "addr", "show"] + output = utils.run_command(ip_cmd) + if ' %s/' % host in output: + # If copying to localhost, don't use SSH + rsync_cmd = ["/usr/bin/rsync", "-av", "--progress", + staging_path, dest_path] + else: + ssh_cmd = 'ssh -o StrictHostKeyChecking=no' + rsync_cmd = ["/usr/bin/rsync", "-av", "--progress", "-e", ssh_cmd, + staging_path, '%s@%s:%s' % (user, host, dest_path)] # NOTE(hillad): rsync's progress is carriage returned, requiring # universal_newlines for real-time output.