diff --git a/packstack/installer/run_setup.py b/packstack/installer/run_setup.py index 8c241d154..3c32c2750 100644 --- a/packstack/installer/run_setup.py +++ b/packstack/installer/run_setup.py @@ -640,7 +640,7 @@ def generateAnswerFile(outputFile, overrides={}): def single_step_aio_install(options): """ Installs an All in One host on this host""" - options.install_hosts = utils.getLocalhostIP() + options.install_hosts = utils.get_localhost_ip() # Also allow the command line to set values for any of these options # by testing if they have been set before we set them here diff --git a/packstack/installer/utils/__init__.py b/packstack/installer/utils/__init__.py index a380c9780..1cd2234f2 100644 --- a/packstack/installer/utils/__init__.py +++ b/packstack/installer/utils/__init__.py @@ -2,7 +2,7 @@ from .datastructures import SortedDict from .decorators import retry -from .network import get_localhost_ip, host2ip, force_ip +from .network import get_localhost_ip, host2ip, force_ip, device_from_ip from .shell import ScriptRunner, execute from .strings import color_text, mask_string @@ -10,5 +10,5 @@ from .strings import color_text, mask_string __all__ = ('SortedDict', 'retry', 'ScriptRunner', 'execute', - 'get_localhost_ip', 'host2ip', 'force_ip', + 'get_localhost_ip', 'host2ip', 'force_ip', 'device_from_ip', 'color_text', 'mask_string') diff --git a/packstack/installer/utils/network.py b/packstack/installer/utils/network.py index 0d12b8bcc..45899837e 100644 --- a/packstack/installer/utils/network.py +++ b/packstack/installer/utils/network.py @@ -3,7 +3,7 @@ import re import socket -from .shell import execute +from .shell import execute, ScriptRunner def get_localhost_ip(): @@ -72,3 +72,14 @@ def force_ip(host, allow_localhost=False): if not ipv4_regex.match(host) or not ipv6_regex.match(host): host = host2ip(host, allow_localhost=allow_localhost) return host + + +def device_from_ip(ip): + server = ScriptRunner() + server.append("DEVICE=$(ip address show to %s | head -n 1 |" + " sed -e 's/.*: \(.*\):.*/\\1/g')" % ip) + # Test device, raises an exception if it doesn't exist + server.append("ip link show \"$DEVICE\" > /dev/null") + server.append("echo $DEVICE") + rv, stdout = server.execute() + return stdout.strip()