Use common utility to wrap IPv6 address
A similar function is provided by oslo_utils.netutils . Change-Id: I6b24ab9deedf9e9802ef1bb5701ddeea91caed69 Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
@@ -478,9 +478,9 @@ def _dhcp_option_file_or_url(task, urlboot=False, ip_version=None,
|
||||
result = boot_file
|
||||
elif urlboot and not http_boot_enabled:
|
||||
if CONF.my_ipv6 and ip_version == 6:
|
||||
host = utils.wrap_ipv6(CONF.my_ipv6)
|
||||
host = netutils.escape_ipv6(CONF.my_ipv6)
|
||||
elif not http_boot_enabled:
|
||||
host = utils.wrap_ipv6(CONF.pxe.tftp_server)
|
||||
host = netutils.escape_ipv6(CONF.pxe.tftp_server)
|
||||
result = "tftp://{host}/{boot_file}".format(host=host,
|
||||
boot_file=boot_file)
|
||||
elif http_boot_enabled:
|
||||
|
||||
@@ -585,17 +585,6 @@ def pop_node_nested_field(node, collection, field, default=None):
|
||||
return result
|
||||
|
||||
|
||||
def wrap_ipv6(ip):
|
||||
"""Wrap the address in square brackets if it's an IPv6 address."""
|
||||
try:
|
||||
if ipaddress.ip_address(ip).version == 6:
|
||||
return "[%s]" % ip
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return ip
|
||||
|
||||
|
||||
def file_mime_type(path):
|
||||
"""Gets a mime type of the given file."""
|
||||
return execute('file', '--brief', '--mime-type', path,
|
||||
|
||||
@@ -32,6 +32,7 @@ from oslo_concurrency import lockutils
|
||||
from oslo_log import log as logging
|
||||
from oslo_service import loopingcall
|
||||
from oslo_utils import fileutils
|
||||
from oslo_utils import netutils
|
||||
import psutil
|
||||
|
||||
from ironic.common import exception
|
||||
@@ -226,7 +227,7 @@ def get_shellinabox_console_url(port):
|
||||
:param port: the terminal port for the node.
|
||||
"""
|
||||
|
||||
console_host = utils.wrap_ipv6(CONF.my_ip)
|
||||
console_host = netutils.escape_ipv6(CONF.my_ip)
|
||||
scheme = 'https' if CONF.console.terminal_cert_dir else 'http'
|
||||
return '%(scheme)s://%(host)s:%(port)s' % {'scheme': scheme,
|
||||
'host': console_host,
|
||||
@@ -384,7 +385,7 @@ def get_socat_console_url(port):
|
||||
:param port: the terminal port (integer) for the node
|
||||
:return: an access URL to the socat console of the node
|
||||
"""
|
||||
console_host = utils.wrap_ipv6(CONF.console.socat_address)
|
||||
console_host = netutils.escape_ipv6(CONF.console.socat_address)
|
||||
return 'tcp://%(host)s:%(port)s' % {'host': console_host,
|
||||
'port': port}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from urllib import parse as urlparse
|
||||
|
||||
from oslo_log import log
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import netutils
|
||||
from oslo_utils import strutils
|
||||
import rfc3986
|
||||
import sushy
|
||||
@@ -28,7 +29,6 @@ import tenacity
|
||||
|
||||
from ironic.common import exception
|
||||
from ironic.common.i18n import _
|
||||
from ironic.common import utils
|
||||
from ironic.conf import CONF
|
||||
from ironic.drivers import utils as driver_utils
|
||||
|
||||
@@ -117,7 +117,11 @@ def parse_driver_info(node):
|
||||
'info': missing_info})
|
||||
|
||||
# Validate the Redfish address
|
||||
address = utils.wrap_ipv6(driver_info['redfish_address'])
|
||||
address = driver_info['redfish_address']
|
||||
|
||||
if isinstance(address, str):
|
||||
address = netutils.escape_ipv6(address)
|
||||
|
||||
try:
|
||||
parsed = rfc3986.uri_reference(address)
|
||||
except TypeError:
|
||||
|
||||
@@ -281,12 +281,6 @@ class GenericUtilsTestCase(base.TestCase):
|
||||
self.assertFalse(utils.is_fips_enabled())
|
||||
m.assert_called_once_with('/proc/sys/crypto/fips_enabled', 'r')
|
||||
|
||||
def test_wrap_ipv6(self):
|
||||
self.assertEqual('[2001:DB8::1]', utils.wrap_ipv6('2001:DB8::1'))
|
||||
self.assertEqual('example.com', utils.wrap_ipv6('example.com'))
|
||||
self.assertEqual('192.168.24.1', utils.wrap_ipv6('192.168.24.1'))
|
||||
self.assertEqual('[2001:DB8::1]', utils.wrap_ipv6('[2001:DB8::1]'))
|
||||
|
||||
|
||||
class TempFilesTestCase(base.TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user