From f7c3ae7970ec370e161de500e02502e577d641da Mon Sep 17 00:00:00 2001 From: "Alexey I. Froloff" Date: Mon, 11 Jul 2016 16:31:09 +0300 Subject: [PATCH] Properly quote IPv6 address in RsyncDriver When IPv6 address literal is used as host in rsync call, it should be enclosed in square brackets. This is already done for copy_file method outside of driver in changeset Ia5f28673e79158d948980f2b3ce496c6a56882af Create helper function format_remote_path(host, path) and use where appropriate. Closes-Bug: 1601822 Change-Id: Ifc386539f33684fb764f5f638a7ee0a10b1ef534 --- nova/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/nova/utils.py b/nova/utils.py index eeeb8ea1c..6a07aae12 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -605,6 +605,20 @@ def safe_ip_format(ip): return ip +def format_remote_path(host, path): + """Returns remote path in format acceptable for scp/rsync. + + If host is IPv6 address literal, return '[host]:path', otherwise + 'host:path' is returned. + + If host is None, only path is returned. + """ + if host is None: + return path + + return "%s:%s" % (safe_ip_format(host), path) + + def monkey_patch(): """If the CONF.monkey_patch set as True, this function patches a decorator