Refactoring: split out wrap_ipv6
While trivial, it's used in several places and will likely be used more as we work on IPv6 support. Change-Id: I10933b8dbadbba87ef6bfa0af767cf1184c072d9
This commit is contained in:
parent
fb79ea2c40
commit
8dc2eebef6
|
@ -20,7 +20,6 @@ from ironic_lib import utils as ironic_utils
|
|||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import fileutils
|
||||
from oslo_utils import netutils
|
||||
|
||||
from ironic.common import dhcp_factory
|
||||
from ironic.common import exception
|
||||
|
@ -388,10 +387,7 @@ def _dhcp_option_file_or_url(task, urlboot=False):
|
|||
if not urlboot:
|
||||
return boot_file
|
||||
elif urlboot:
|
||||
if netutils.is_valid_ipv6(CONF.pxe.tftp_server):
|
||||
host = "[%s]" % CONF.pxe.tftp_server
|
||||
else:
|
||||
host = CONF.pxe.tftp_server
|
||||
host = utils.wrap_ipv6(CONF.pxe.tftp_server)
|
||||
return "tftp://{host}/{boot_file}".format(host=host,
|
||||
boot_file=boot_file)
|
||||
|
||||
|
|
|
@ -558,3 +558,10 @@ def pop_node_nested_field(node, collection, field, default=None):
|
|||
result = col.pop(field, default)
|
||||
setattr(node, collection, col)
|
||||
return result
|
||||
|
||||
|
||||
def wrap_ipv6(ip):
|
||||
"""Wrap the address in square brackets if it's an IPv6 address."""
|
||||
if netutils.is_valid_ipv6(ip):
|
||||
return "[%s]" % ip
|
||||
return ip
|
||||
|
|
|
@ -37,6 +37,7 @@ import psutil
|
|||
|
||||
from ironic.common import exception
|
||||
from ironic.common.i18n import _
|
||||
from ironic.common import utils
|
||||
from ironic.conf import CONF
|
||||
|
||||
|
||||
|
@ -207,9 +208,7 @@ def get_shellinabox_console_url(port):
|
|||
:param port: the terminal port for the node.
|
||||
"""
|
||||
|
||||
console_host = CONF.my_ip
|
||||
if netutils.is_valid_ipv6(console_host):
|
||||
console_host = '[%s]' % console_host
|
||||
console_host = utils.wrap_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,
|
||||
|
@ -367,10 +366,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 = CONF.console.socat_address
|
||||
if netutils.is_valid_ipv6(console_host):
|
||||
console_host = '[%s]' % console_host
|
||||
|
||||
console_host = utils.wrap_ipv6(CONF.console.socat_address)
|
||||
return 'tcp://%(host)s:%(port)s' % {'host': console_host,
|
||||
'port': port}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ from ironic_lib import metrics_utils
|
|||
from oslo_concurrency import processutils
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import netutils
|
||||
|
||||
from ironic.common import dhcp_factory
|
||||
from ironic.common import exception
|
||||
|
@ -65,18 +64,13 @@ def _save_disk_layout(node, i_info):
|
|||
node.save()
|
||||
|
||||
|
||||
def _wrap_ipv6(ip):
|
||||
if netutils.is_valid_ipv6(ip):
|
||||
return "[%s]" % ip
|
||||
return ip
|
||||
|
||||
|
||||
def discovery(portal_address, portal_port):
|
||||
"""Do iSCSI discovery on portal."""
|
||||
utils.execute('iscsiadm',
|
||||
'-m', 'discovery',
|
||||
'-t', 'st',
|
||||
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
|
||||
'-p', '%s:%s' % (utils.wrap_ipv6(portal_address),
|
||||
portal_port),
|
||||
run_as_root=True,
|
||||
check_exit_code=[0],
|
||||
attempts=5,
|
||||
|
@ -87,7 +81,8 @@ def login_iscsi(portal_address, portal_port, target_iqn):
|
|||
"""Login to an iSCSI target."""
|
||||
utils.execute('iscsiadm',
|
||||
'-m', 'node',
|
||||
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
|
||||
'-p', '%s:%s' % (utils.wrap_ipv6(portal_address),
|
||||
portal_port),
|
||||
'-T', target_iqn,
|
||||
'--login',
|
||||
run_as_root=True,
|
||||
|
@ -186,7 +181,8 @@ def logout_iscsi(portal_address, portal_port, target_iqn):
|
|||
"""Logout from an iSCSI target."""
|
||||
utils.execute('iscsiadm',
|
||||
'-m', 'node',
|
||||
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
|
||||
'-p', '%s:%s' % (utils.wrap_ipv6(portal_address),
|
||||
portal_port),
|
||||
'-T', target_iqn,
|
||||
'--logout',
|
||||
run_as_root=True,
|
||||
|
@ -201,7 +197,8 @@ def delete_iscsi(portal_address, portal_port, target_iqn):
|
|||
# no longer a target to delete (exit code 21).
|
||||
utils.execute('iscsiadm',
|
||||
'-m', 'node',
|
||||
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
|
||||
'-p', '%s:%s' % (utils.wrap_ipv6(portal_address),
|
||||
portal_port),
|
||||
'-T', target_iqn,
|
||||
'-o', 'delete',
|
||||
run_as_root=True,
|
||||
|
|
Loading…
Reference in New Issue