rtstool surrounds IPv6 addresses by brackets

Currently rtstool fails to create rtslib_fb.NetworkPortal with IPv6
addresses because rtslib expects IPv6 addresses to be surrounded by
brackets.

mitaka-backport-potential

Closes-Bug: #1562737
Change-Id: I3cffde726ecbb1ddea77d57bd7edd02792872ea6
This commit is contained in:
Sergey Gotliv
2016-03-28 11:01:43 +03:00
parent 6a6e5a15dc
commit 4f1300cbae
2 changed files with 34 additions and 23 deletions

View File

@@ -82,14 +82,15 @@ def create(backing_device, name, userid, password, iser_enabled,
# If no ips are given we'll bind to all IPv4 and v6
if not portals_ips:
portals_ips = ('0.0.0.0', '::0')
portals_ips = ('0.0.0.0', '[::0]')
# TODO(emh): Binding to IPv6 fails sometimes -- let pass for now.
ips_allow_fail = ('::0',)
ips_allow_fail = ('[::0]',)
for ip in portals_ips:
try:
portal = rtslib_fb.NetworkPortal(tpg_new, ip, portals_port,
mode='any')
# rtslib expects IPv6 addresses to be surrounded by brackets
portal = rtslib_fb.NetworkPortal(tpg_new, _canonicalize_ip(ip),
portals_port, mode='any')
except rtslib_fb.utils.RTSLibError:
raise_exc = ip not in ips_allow_fail
msg_type = 'Error' if raise_exc else 'Warning'
@@ -258,6 +259,12 @@ def parse_optional_create(argv):
return optional_args
def _canonicalize_ip(ip):
if ip.startswith('[') or "." in ip:
return ip
return "[" + ip + "]"
def main(argv=None):
if argv is None:
argv = sys.argv