From a292eb8d8774cb6db6e2c76b9f4af33d8a9bb945 Mon Sep 17 00:00:00 2001 From: Paul Nilsson Date: Tue, 17 Sep 2024 11:53:13 +0200 Subject: [PATCH] Improved IPv6 info extraction --- PILOTVERSION | 2 +- pilot/util/constants.py | 2 +- pilot/util/networking.py | 26 +++++++++++++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/PILOTVERSION b/PILOTVERSION index bd3ffbfc..ebf6e6f6 100644 --- a/PILOTVERSION +++ b/PILOTVERSION @@ -1 +1 @@ -3.8.2.1 \ No newline at end of file +3.8.2.2 \ No newline at end of file diff --git a/pilot/util/constants.py b/pilot/util/constants.py index 9e37aba5..8c0bcef3 100644 --- a/pilot/util/constants.py +++ b/pilot/util/constants.py @@ -28,7 +28,7 @@ RELEASE = '3' # released number should be fixed at 3 for Pilot 3 VERSION = '8' # version number is '1' for first release, '0' until then, increased for bigger updates REVISION = '2' # revision number should be reset to '0' for every new version release, increased for small updates -BUILD = '1' # build number should be reset to '1' for every new development cycle +BUILD = '2' # build number should be reset to '1' for every new development cycle SUCCESS = 0 FAILURE = 1 diff --git a/pilot/util/networking.py b/pilot/util/networking.py index 5e03368d..d081b784 100644 --- a/pilot/util/networking.py +++ b/pilot/util/networking.py @@ -35,7 +35,7 @@ def dump_ipv6_info() -> None: """Dump the IPv6 info to the log.""" cmd = 'ifconfig' if not is_command_available(cmd): - _cmd = '/usr/sbin/ifconfig' + _cmd = '/usr/sbin/ifconfig -a' if not is_command_available(_cmd): logger.warning(f'command {cmd} is not available - this WN might not support IPv6') return @@ -43,15 +43,35 @@ def dump_ipv6_info() -> None: _, stdout, stderr = execute(cmd, timeout=10) if stdout: - ipv6 = extract_ipv6(stdout) + ipv6 = extract_ipv6_addresses(stdout) if ipv6: logger.info(f'IPv6 addresses: {ipv6}') else: - logger.warning('no IPv6 addresses found - this WN does not support IPv6') + logger.warning('no IPv6 addresses were found') else: logger.warning(f'failed to run ifconfig: {stderr}') +def extract_ipv6_addresses(ifconfig_output: str) -> list: + """Extracts IPv6 addresses from ifconfig output. + + Args: + ifconfig_output: The output of the ifconfig command. + + Returns: + A list of IPv6 addresses. + """ + + ipv6_addresses = [] + for line in ifconfig_output.splitlines(): + line = line.strip().replace("\t", " ").replace("\r", "").replace("\n", "") + match = re.search(r"inet6 (.*?)\s", line) + if match and match.group(1) != "::1": # skip loopback address + ipv6_addresses.append(match.group(1)) + + return ipv6_addresses + + def extract_ipv6(ifconfig: str) -> str: """ Extract the IPv6 address from the ifconfig output.