Skip to content

Commit

Permalink
Improved IPv6 info extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Nilsson committed Sep 17, 2024
1 parent df9a4d9 commit a292eb8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion PILOTVERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.2.1
3.8.2.2
2 changes: 1 addition & 1 deletion pilot/util/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions pilot/util/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,43 @@ 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
cmd = _cmd

_, 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.
Expand Down

0 comments on commit a292eb8

Please sign in to comment.