ServerConnection#

class ansys.additive.core.server_connection.server_connection.ServerConnection(transport_mode: ansys.additive.core.server_connection.constants.TransportMode | str | None = None, certs_dir: pathlib.Path | str | None = None, uds_dir: pathlib.Path | str | None = None, uds_id: str | None = None, allow_remote_host: bool = False, channel: grpc.Channel | None = None, addr: str | None = None, product_version: str = DEFAULT_PRODUCT_VERSION, log: logging.Logger | None = None, linux_install_path: os.PathLike | None = None)#

Provides connection to Additive server.

If neither channel nor addr are provided, an attempt is made to start an Additive server and connect to it. Starting a server in a cloud environment requires PyPIM to be available. To start a server when running on localhost, the Additive option of the Structures package of the Ansys unified installation must be installed.

Parameters:
transport_modeTransportMode | str

The transport mode to use for the connection. Can be a member of the TransportMode enum or a string (‘insecure’, ‘mtls’, or ‘uds’).

certs_dirPath | str | None

Directory containing certificates for mTLS connections. Required if transport_mode is ‘mtls’.

uds_dirPath | str | None

Directory containing Unix Domain Socket files. Required if transport_mode is ‘uds’.

uds_idstr | None

Identifier for the Unix Domain Socket. Required if transport_mode is ‘uds’.

allow_remote_host: bool

Whether to allow connections to remote hosts when using ‘insecure’ or ‘mtls’ transport modes.

channel: grpc.Channel, None

gRPC channel connected to server.

addr: str, None

IPv4 address of server of the form host:port.

product_version: str

Version of the Ansys product installation in the form "YYR", where YY is the two-digit year and R is the release number. For example, the release 2024 R1 would be specified as 241. This parameter is only applicable in PyPIM-enabled cloud environments and on localhost.

log: logging.Logger, None

Log to write connection messages to.

linux_install_path: os.PathLike, None default: None

Path to the Ansys installation directory on Linux. This parameter is only required when Ansys has not been installed in the default location. Example: /usr/shared/ansys_inc. Note that the path should not include the product version.

Overview#

disconnect

Clean up server connection.

status

Return the server connection status.

ready

Return whether the server is ready.

channel_str

GRPC channel target.

materials_stub

Materials service stub.

simulation_stub

Simulation service stub.

operations_stub

Operations service stub.

settings_stub

Settings service stub.

uds_file

Path to the Unix Domain Socket file if using ‘uds’ transport mode, otherwise None.

__del__

Disconnect from server.

Import detail#

from ansys.additive.core.server_connection.server_connection import ServerConnection

Property detail#

property ServerConnection.channel_str: str#

GRPC channel target.

The form is generally "ip:port". For example, "127.0.0.1:50052". In the case of UDS channels, the form is the path to the UDS socket file.

property ServerConnection.materials_stub: ansys.api.additive.v0.additive_materials_pb2_grpc.MaterialsServiceStub#

Materials service stub.

property ServerConnection.simulation_stub: ansys.api.additive.v0.additive_simulation_pb2_grpc.SimulationServiceStub#

Simulation service stub.

property ServerConnection.operations_stub: google.longrunning.operations_pb2_grpc.OperationsStub#

Operations service stub.

property ServerConnection.settings_stub: ansys.api.additive.v0.additive_settings_pb2_grpc.SettingsServiceStub#

Settings service stub.

property ServerConnection.uds_file: pathlib.Path | None#

Path to the Unix Domain Socket file if using ‘uds’ transport mode, otherwise None.

Method detail#

ServerConnection.__del__() None#

Disconnect from server.

ServerConnection.disconnect()#

Clean up server connection.

ServerConnection.status() ServerConnectionStatus#

Return the server connection status.

ServerConnection.ready(retries: int = 5) bool#

Return whether the server is ready.

Parameters:
retries: int

Number of times to retry before giving up. An linearly increasing delay is used between each retry.

Returns:
bool:

True means server is ready. False means the number of retries was exceeded without receiving a response from the server.