cfx_container#
Provides a module for launching and configuring local CFX Docker container runs.
Notes#
For configuration information, see the configure_container_dict() function. For a
list of additional Docker container run configuration options that can also be specified
through the container_dict argument for the
launch_cfx() function, see Docker run in the Docker
SDK for Python containers documentation
For the CFX Docker container to be able to find license information, the license file or server
needs to be specified through the ANSYSLMD_LICENSE_FILE environment variable, or the
license_server argument for the container_dict (see configure_container_dict()).
Examples#
Launch a CFX Docker container with the system default configuration:
>>> import ansys.cfx.core as pycfx
>>> session = pycfx.launch_cfx(start_container=True)
Launch with a custom configuration, using cfx_image and host_mount_path,
which are arguments for the configure_container_dict() function. auto_remove is
an argument for Docker run:
>>> import ansys.cfx.core as pycfx
>>> custom_config = {}
>>> custom_config.update(cfx_image='custom_cfx:v25.2.3', host_mount_path='/testing',
... auto_remove=False)
>>> session = pycfx.launch_cfx(container_dict=custom_config)
Get the default CFX Docker container configuration and then launch with the customized configuration:
>>> import ansys.cfx.core as pycfx
>>> config_dict = pycfx.launch_cfx(start_container=True, dry_run=True)
Docker container run configuration information:
config_dict =
{'auto_remove': True,
'command': ['-py', '-sifile /mnt/pycfx/serverinfo-lpqsdldw.txt'],
'detach': True,
'environment': {'ANSYSLMD_LICENSE_FILE': '2048@licenseserver.com',
'REMOTING_PORTS': '54000/portspan=2'},
'cfx_image': 'ghcr.io/ansys/pycfx:v25.2.3',
'labels': {'test_name': 'none'},
'ports': {'54000': 54000},
'volumes': ['/home/user/.local/share/ansys_cfx_core/examples:/mnt/pycfx'],
'working_dir': '/mnt/pycfx'}
>>> config_dict.update(image_name='custom_cfx', image_tag='v25.2.3', mem_limit='1g')
>>> session = pycfx.launch_cfx(container_dict=config_dict)
Exceptions:
Raised when a CFX session command is not specified. |
|
Raised when the CFX image name or image tag is not specified. |
|
Raised when the license server is not specified. |
|
Raised when the server information file is not given properly. |
Functions:
|
Parse the following parameters and set up the container configuration file. |
|
Extract host and container mount paths from a container configuration dictionary. |
|
Replace the first occurrence of a container path in the given line with its corresponding host path. |
|
Replace the first occurrence of a host path in the given line with its corresponding container path. |
|
Start a CFX container. |
- exception ansys.cfx.core.launcher.cfx_container.CFXCommandNotSpecified#
Bases:
ValueErrorRaised when a CFX session command is not specified.
Methods:
__init__()- __init__()#
- exception ansys.cfx.core.launcher.cfx_container.CFXImageNameTagNotSpecified#
Bases:
ValueErrorRaised when the CFX image name or image tag is not specified.
Methods:
__init__()- __init__()#
- exception ansys.cfx.core.launcher.cfx_container.LicenseServerNotSpecified#
Bases:
KeyErrorRaised when the license server is not specified.
Methods:
__init__()- __init__()#
- exception ansys.cfx.core.launcher.cfx_container.ServerInfoFileError#
Bases:
ValueErrorRaised when the server information file is not given properly.
Methods:
__init__()- __init__()#
- ansys.cfx.core.launcher.cfx_container.configure_container_dict(args: List[str], host_mount_path: str | Path | None = None, container_mount_path: str | Path | None = None, timeout: int = 240, port: int | None = None, license_server: str | None = None, container_server_info_file: str | Path | None = None, remove_server_info_file: bool = True, cfx_image: str | None = None, image_name: str | None = None, image_tag: str | None = None, has_remote_server: bool = True, **container_dict) tuple[dict, int, int, Path, bool]#
Parse the following parameters and set up the container configuration file.
- Parameters:
- args
List[str] List of CFX launch arguments.
- host_mount_path
Union[str,Path], default:None Existing path in the host operating system that is available inside the container.
- container_mount_path
Union[str,Path], default:None Path inside the container where the host mount path is mounted to.
- timeout
int, default:None Time limit in seconds for the CFX container to start. When
None, 30 seconds is used.- port
int, default:None Port for CFX container to use.
- license_server
str, default:None License server for Ansys CFX to use.
- container_server_info_file
Union[str,Path], default:None Name of the server information file for CFX to write on the
host_mount_pathargument.- remove_server_info_filebool, default:
True Whether to automatically delete the server information file after PyCFX has finished using it.
- has_remote_serverbool, default:
True Whether to create a server information file for server and client communication setup.
- cfx_image
str, default:None Specifies full image name for Docker container run, with the format
"image_name:image_tag". Theimage_tagandimage_nameparameters are ignored if thecfx_imageparameter has been specified.- image_name
str, default:None Ignored if the
cfx_imageparameter has been specified.- image_tag
str, default:None Ignored if the
cfx_imageparameter has been specified.- **container_dict
Additional keyword arguments that can be specified. They are treated as Docker container run options to be passed directly to the Docker run execution. See the following examples and Docker run documentation.
- args
- Returns:
- Raises:
LicenseServerNotSpecifiedIf license server is not specified through an environment variable or in
container_dict.ServerInfoFileErrorIf server information file is specified through both a command-line argument inside
container_dictand thecontainer_server_info_fileparameter.CFXImageNameTagNotSpecifiedIf
cfx_imageorimage_tagandimage_nameare not specified.CFXCommandNotSpecifiedIf
cfx_cmdis not specified.
Notes
This function should usually not be called directly. It is automatically used by the
launch_cfx()function.For a list of additional Docker container run configuration options that can also be specified using
container_dict, see Docker run documentation.See also the
start_cfx_container()function.
- ansys.cfx.core.launcher.cfx_container.extract_mount_paths(container_dict: dict) dict#
Extract host and container mount paths from a container configuration dictionary.
This function looks for a “volumes” key in the input dictionary. If present, it expects the value to be a list of volume specifications. It extracts mount paths for test home mounts and temp directory mounts from the first two volumes (if available).
Returns a dictionary with the following keys:
host_mount_path: Path on the host for the first volume (orNone).container_mount_path: Path in the container for the first volume (orNone).host_temporary_directory_path: Path on the host for the second volume (orNone).container_temporary_directory_path: Path in the container for the second volume (orNone).
- ansys.cfx.core.launcher.cfx_container.replace_container_path_with_host_path(line: str, mount_paths: dict[str, str]) str#
Replace the first occurrence of a container path in the given line with its corresponding host path.
- ansys.cfx.core.launcher.cfx_container.replace_host_path_with_container_path(line: str, mount_paths: dict[str, str]) str#
Replace the first occurrence of a host path in the given line with its corresponding container path.
- ansys.cfx.core.launcher.cfx_container.start_cfx_container(args: List[str], container_dict: dict | None = None) tuple[int, str]#
Start a CFX container.
- Parameters:
- Returns:
tupleEither:
(str, str): For Unix domain socket server address.
(str, int, str): For TCP/IP server address.
- Raises:
TimeoutErrorIf the CFX container launch reaches timeout.
Notes
Uses
configure_container_dict()to parse the optionalcontainer_dictconfiguration.This function should usually not be called directly. It is automatically used by the
launch_cfx()function.