Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
check_valid_ip,
check_valid_port,
create_temp_dir,
parse_ip_route,
)
from ansys.mapdl.core.misc import threaded # type: ignore
from ansys.mapdl.core.plotting import GraphicsBackend
Expand Down Expand Up @@ -2025,7 +2026,7 @@ def set_license_switch(license_type: str | None, additional_switches: str) -> st
def _get_windows_host_ip() -> str | None:
output = _run_ip_route()
if output:
return _parse_ip_route(output)
return parse_ip_route(output)


def _run_ip_route() -> str | None:
Expand All @@ -2045,13 +2046,6 @@ def _run_ip_route() -> str | None:
return p.stdout.decode()


def _parse_ip_route(output: str) -> str | None:
match = re.findall(r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*", output)

if match:
return match[0]


def get_slurm_options(
args: Dict[str, Any],
kwargs: Dict[str, Any],
Expand Down
7 changes: 7 additions & 0 deletions src/ansys/mapdl/core/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ def check_valid_ip(ip: str) -> None:
socket.inet_aton(ip)


def parse_ip_route(output: str) -> str | None:
match = re.findall(r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*", output)

if match:
Comment thread
germa89 marked this conversation as resolved.
return match[0]


def check_valid_port(
port: int, lower_bound: int = 1000, high_bound: int = 60000
) -> None:
Expand Down
7 changes: 3 additions & 4 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
_HAS_ATP,
LOCALHOST,
_is_ubuntu,
_parse_ip_route,
check_mapdl_launch_on_hpc,
check_mode,
force_smp_in_student,
Expand Down Expand Up @@ -77,7 +76,7 @@
update_env_vars,
)
from ansys.mapdl.core.licensing import LICENSES
from ansys.mapdl.core.misc import check_has_mapdl, stack
from ansys.mapdl.core.misc import check_has_mapdl, parse_ip_route, stack
from conftest import (
ON_LOCAL,
PATCH_MAPDL,
Expand Down Expand Up @@ -589,13 +588,13 @@ def test__parse_ip_route():
output = """default via 172.25.192.1 dev eth0 proto kernel <<<=== this
172.25.192.0/20 dev eth0 proto kernel scope link src 172.25.195.101 <<<=== not this"""

assert "172.25.192.1" == _parse_ip_route(output)
assert "172.25.192.1" == parse_ip_route(output)

output = """
default via 172.23.112.1 dev eth0 proto kernel
172.23.112.0/20 dev eth0 proto kernel scope link src 172.23.121.145"""

assert "172.23.112.1" == _parse_ip_route(output)
assert "172.23.112.1" == parse_ip_route(output)


def test_launched(mapdl, cleared):
Expand Down
Loading