Skip to content

Commit e19f25f

Browse files
hpohekarpyansys-ci-botjerome-blancheCopilot
authored
fix: Ansys Lab authentication (#4503)
Resolved Ansys Lab authentication issue. --------- Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: Jérôme Blanche <90267895+jerome-blanche@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5eedcc9 commit e19f25f

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

doc/changelog.d/4503.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ansys Lab authentication

src/ansys/fluent/core/launcher/pim_launcher.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import inspect
3939
import logging
4040
import os
41+
import tempfile
42+
import time
4143
from typing import Any, Dict
4244

4345
from ansys.fluent.core.fluent_connection import FluentConnection, _get_max_c_int_limit
@@ -50,6 +52,7 @@
5052
UIMode,
5153
_get_argvals_and_session,
5254
)
55+
from ansys.fluent.core.session import _parse_server_info_file
5356
from ansys.fluent.core.session_meshing import Meshing
5457
from ansys.fluent.core.session_pure_meshing import PureMeshing
5558
from ansys.fluent.core.session_solver import Solver
@@ -193,6 +196,54 @@ def __call__(self):
193196
)
194197

195198

199+
def get_ip_port_password(
200+
file_service,
201+
filename="sifile.txt",
202+
max_retries=20,
203+
wait_time_between_retries=1, # seconds
204+
):
205+
"""
206+
Downloads the file with retries and parses server info.
207+
208+
Parameters
209+
----------
210+
file_service: PimFileTransferService
211+
Service object with method download_file(filename, target_dir).
212+
filename: str
213+
Name of the file to download.
214+
max_retries: int
215+
Maximum number of attempts.
216+
wait_time_between_retries: float
217+
Seconds to wait between retries (can be fractional, e.g., 0.5 for half a second).
218+
219+
Returns
220+
-------
221+
Tuple (ip, port, password) parsed from the downloaded file.
222+
223+
Raises
224+
------
225+
TimeoutError
226+
If unable to download the server info file after multiple retries.
227+
"""
228+
with tempfile.TemporaryDirectory(prefix="fluent_sifile_") as tmpdir:
229+
for attempt in range(1, max_retries + 1):
230+
try:
231+
file_service.download_file(filename, tmpdir)
232+
break
233+
except Exception as ex:
234+
logger.warning(
235+
f"Attempt {attempt} of {max_retries} failed to download {filename}: {ex}"
236+
)
237+
if attempt == max_retries:
238+
raise TimeoutError(
239+
f"Failed to download file '{filename}' after {max_retries} attempts "
240+
f"with {wait_time_between_retries}s between retries."
241+
) from ex
242+
time.sleep(wait_time_between_retries)
243+
244+
return _parse_server_info_file(os.path.join(tmpdir, filename))
245+
246+
196247
def launch_remote_fluent(
197248
session_cls,
198249
start_transcript: bool,
@@ -232,6 +283,11 @@ def launch_remote_fluent(
232283
-------
233284
Meshing | PureMeshing | Solver | SolverIcing
234285
Session object.
286+
287+
Raises
288+
------
289+
TimeoutError
290+
If unable to download the server info file after multiple retries.
235291
"""
236292

237293
pim = pypim.connect()
@@ -245,6 +301,10 @@ def launch_remote_fluent(
245301

246302
instance.wait_for_ready()
247303

304+
ip, port, password = get_ip_port_password(
305+
file_service=PimFileTransferService(pim_instance=instance)
306+
)
307+
248308
channel = instance.build_grpc_channel(
249309
options=[
250310
("grpc.max_send_message_length", _get_max_c_int_limit()),
@@ -253,6 +313,9 @@ def launch_remote_fluent(
253313
)
254314

255315
fluent_connection = create_fluent_connection(
316+
ip=ip,
317+
port=port,
318+
password=password,
256319
channel=channel,
257320
cleanup_on_exit=cleanup_on_exit,
258321
instance=instance,
@@ -288,11 +351,20 @@ def create_fluent_instance(
288351

289352

290353
def create_fluent_connection(
291-
channel, cleanup_on_exit: bool, instance, launcher_args: Dict[str, Any] | None
354+
ip: str,
355+
port: int,
356+
password: str,
357+
channel,
358+
cleanup_on_exit: bool,
359+
instance,
360+
launcher_args: Dict[str, Any] | None,
292361
):
293362
"""Create a Fluent connection."""
294363

295364
return FluentConnection(
365+
ip=ip,
366+
port=port,
367+
password=password,
296368
channel=channel,
297369
cleanup_on_exit=cleanup_on_exit,
298370
remote_instance=instance,

0 commit comments

Comments
 (0)