Merge "Refactoring: split out wrap_ipv6"
This commit is contained in:
commit
8a2866f25f
@ -20,7 +20,6 @@ from ironic_lib import utils as ironic_utils
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
from oslo_utils import fileutils
|
from oslo_utils import fileutils
|
||||||
from oslo_utils import netutils
|
|
||||||
|
|
||||||
from ironic.common import dhcp_factory
|
from ironic.common import dhcp_factory
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
@ -388,10 +387,7 @@ def _dhcp_option_file_or_url(task, urlboot=False):
|
|||||||
if not urlboot:
|
if not urlboot:
|
||||||
return boot_file
|
return boot_file
|
||||||
elif urlboot:
|
elif urlboot:
|
||||||
if netutils.is_valid_ipv6(CONF.pxe.tftp_server):
|
host = utils.wrap_ipv6(CONF.pxe.tftp_server)
|
||||||
host = "[%s]" % CONF.pxe.tftp_server
|
|
||||||
else:
|
|
||||||
host = CONF.pxe.tftp_server
|
|
||||||
return "tftp://{host}/{boot_file}".format(host=host,
|
return "tftp://{host}/{boot_file}".format(host=host,
|
||||||
boot_file=boot_file)
|
boot_file=boot_file)
|
||||||
|
|
||||||
|
@ -558,3 +558,10 @@ def pop_node_nested_field(node, collection, field, default=None):
|
|||||||
result = col.pop(field, default)
|
result = col.pop(field, default)
|
||||||
setattr(node, collection, col)
|
setattr(node, collection, col)
|
||||||
return result
|
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 import exception
|
||||||
from ironic.common.i18n import _
|
from ironic.common.i18n import _
|
||||||
|
from ironic.common import utils
|
||||||
from ironic.conf import CONF
|
from ironic.conf import CONF
|
||||||
|
|
||||||
|
|
||||||
@ -207,9 +208,7 @@ def get_shellinabox_console_url(port):
|
|||||||
:param port: the terminal port for the node.
|
:param port: the terminal port for the node.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
console_host = CONF.my_ip
|
console_host = utils.wrap_ipv6(CONF.my_ip)
|
||||||
if netutils.is_valid_ipv6(console_host):
|
|
||||||
console_host = '[%s]' % console_host
|
|
||||||
scheme = 'https' if CONF.console.terminal_cert_dir else 'http'
|
scheme = 'https' if CONF.console.terminal_cert_dir else 'http'
|
||||||
return '%(scheme)s://%(host)s:%(port)s' % {'scheme': scheme,
|
return '%(scheme)s://%(host)s:%(port)s' % {'scheme': scheme,
|
||||||
'host': console_host,
|
'host': console_host,
|
||||||
@ -367,10 +366,7 @@ def get_socat_console_url(port):
|
|||||||
:param port: the terminal port (integer) for the node
|
:param port: the terminal port (integer) for the node
|
||||||
:return: an access URL to the socat console of the node
|
:return: an access URL to the socat console of the node
|
||||||
"""
|
"""
|
||||||
console_host = CONF.console.socat_address
|
console_host = utils.wrap_ipv6(CONF.console.socat_address)
|
||||||
if netutils.is_valid_ipv6(console_host):
|
|
||||||
console_host = '[%s]' % console_host
|
|
||||||
|
|
||||||
return 'tcp://%(host)s:%(port)s' % {'host': console_host,
|
return 'tcp://%(host)s:%(port)s' % {'host': console_host,
|
||||||
'port': port}
|
'port': port}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ from ironic_lib import metrics_utils
|
|||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
from oslo_utils import netutils
|
|
||||||
|
|
||||||
from ironic.common import dhcp_factory
|
from ironic.common import dhcp_factory
|
||||||
from ironic.common import exception
|
from ironic.common import exception
|
||||||
@ -65,18 +64,13 @@ def _save_disk_layout(node, i_info):
|
|||||||
node.save()
|
node.save()
|
||||||
|
|
||||||
|
|
||||||
def _wrap_ipv6(ip):
|
|
||||||
if netutils.is_valid_ipv6(ip):
|
|
||||||
return "[%s]" % ip
|
|
||||||
return ip
|
|
||||||
|
|
||||||
|
|
||||||
def discovery(portal_address, portal_port):
|
def discovery(portal_address, portal_port):
|
||||||
"""Do iSCSI discovery on portal."""
|
"""Do iSCSI discovery on portal."""
|
||||||
utils.execute('iscsiadm',
|
utils.execute('iscsiadm',
|
||||||
'-m', 'discovery',
|
'-m', 'discovery',
|
||||||
'-t', 'st',
|
'-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,
|
run_as_root=True,
|
||||||
check_exit_code=[0],
|
check_exit_code=[0],
|
||||||
attempts=5,
|
attempts=5,
|
||||||
@ -87,7 +81,8 @@ def login_iscsi(portal_address, portal_port, target_iqn):
|
|||||||
"""Login to an iSCSI target."""
|
"""Login to an iSCSI target."""
|
||||||
utils.execute('iscsiadm',
|
utils.execute('iscsiadm',
|
||||||
'-m', 'node',
|
'-m', 'node',
|
||||||
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
|
'-p', '%s:%s' % (utils.wrap_ipv6(portal_address),
|
||||||
|
portal_port),
|
||||||
'-T', target_iqn,
|
'-T', target_iqn,
|
||||||
'--login',
|
'--login',
|
||||||
run_as_root=True,
|
run_as_root=True,
|
||||||
@ -186,7 +181,8 @@ def logout_iscsi(portal_address, portal_port, target_iqn):
|
|||||||
"""Logout from an iSCSI target."""
|
"""Logout from an iSCSI target."""
|
||||||
utils.execute('iscsiadm',
|
utils.execute('iscsiadm',
|
||||||
'-m', 'node',
|
'-m', 'node',
|
||||||
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
|
'-p', '%s:%s' % (utils.wrap_ipv6(portal_address),
|
||||||
|
portal_port),
|
||||||
'-T', target_iqn,
|
'-T', target_iqn,
|
||||||
'--logout',
|
'--logout',
|
||||||
run_as_root=True,
|
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).
|
# no longer a target to delete (exit code 21).
|
||||||
utils.execute('iscsiadm',
|
utils.execute('iscsiadm',
|
||||||
'-m', 'node',
|
'-m', 'node',
|
||||||
'-p', '%s:%s' % (_wrap_ipv6(portal_address), portal_port),
|
'-p', '%s:%s' % (utils.wrap_ipv6(portal_address),
|
||||||
|
portal_port),
|
||||||
'-T', target_iqn,
|
'-T', target_iqn,
|
||||||
'-o', 'delete',
|
'-o', 'delete',
|
||||||
run_as_root=True,
|
run_as_root=True,
|
||||||
|
Loading…
Reference in New Issue
Block a user