|
32 | 32 | import functools |
33 | 33 | import inspect |
34 | 34 | import os |
| 35 | +from pathlib import Path |
35 | 36 | import platform |
36 | 37 | import socket |
37 | 38 | import sys |
|
43 | 44 | from ansys import dpf |
44 | 45 | from ansys.dpf.core import errors, server_context |
45 | 46 | from ansys.dpf.core.misc import get_ansys_path, is_ubuntu |
| 47 | +from ansys.dpf.core.server_context import ServerContext |
46 | 48 | from ansys.dpf.core.server_factory import ( |
47 | 49 | CommunicationProtocols, |
| 50 | + DockerConfig, |
48 | 51 | GrpcMode, |
49 | 52 | ServerConfig, |
50 | 53 | ServerFactory, |
@@ -158,63 +161,76 @@ def shutdown_all_session_servers(): |
158 | 161 |
|
159 | 162 |
|
160 | 163 | def start_local_server( |
161 | | - ip=LOCALHOST, |
162 | | - port=DPF_DEFAULT_PORT, |
163 | | - ansys_path=None, |
164 | | - as_global=True, |
165 | | - load_operators=True, |
166 | | - use_docker_by_default=True, |
167 | | - docker_config=RUNNING_DOCKER, |
168 | | - timeout=20.0, |
169 | | - config=None, |
170 | | - use_pypim_by_default=True, |
171 | | - context=None, |
| 164 | + ip: str = LOCALHOST, |
| 165 | + port: int = DPF_DEFAULT_PORT, |
| 166 | + ansys_path: Path | str = None, |
| 167 | + as_global: bool = True, |
| 168 | + load_operators: bool = True, |
| 169 | + use_docker_by_default: bool = True, |
| 170 | + docker_config: DockerConfig = RUNNING_DOCKER, |
| 171 | + timeout: float = 20.0, |
| 172 | + config: ServerConfig = None, |
| 173 | + use_pypim_by_default: bool = True, |
| 174 | + context: ServerContext = None, |
172 | 175 | ) -> AnyServerType: |
173 | 176 | """Start a new local DPF server at a given port and IP address. |
174 | 177 |
|
175 | 178 | This method requires Windows and ANSYS 2021 R1 or later. If ``as_global=True``, which is |
176 | 179 | the default) the server is stored globally, replacing the one stored previously. |
177 | 180 | Otherwise, a user must keep a handle on their server. |
178 | 181 |
|
| 182 | + .. warning:: |
| 183 | + Starting with DPF 2026 R1 and PyDPF 0.15.0, the default gRPC server uses mTLS authentication. |
| 184 | + Please refer to :ref:`ref_dpf_server_secure_mode` for more information on how to set up the |
| 185 | + certificates and configure the server and client accordingly. |
| 186 | + See the ``config`` parameter for more details. |
| 187 | +
|
179 | 188 | Parameters |
180 | 189 | ---------- |
181 | | - ip : str, optional |
| 190 | + ip: |
182 | 191 | IP address of the remote or local instance to connect to. The |
183 | 192 | default is ``"LOCALHOST"``. |
184 | | - port : int, optional |
| 193 | + port: |
185 | 194 | Port to connect to the remote instance on. The default is |
186 | 195 | ``"DPF_DEFAULT_PORT"``, which is 50054. |
187 | | - ansys_path : str or os.PathLike, optional |
| 196 | + ansys_path: |
188 | 197 | Root path for the Ansys installation directory. For example, ``"/ansys_inc/v212/"``. |
189 | 198 | The default is the latest Ansys installation. |
190 | | - as_global : bool, optional |
| 199 | + as_global: |
191 | 200 | Global variable that stores the IP address and port for the DPF |
192 | 201 | module. All DPF objects created in this Python session will |
193 | 202 | use this IP and port. The default is ``True``. |
194 | | - load_operators : bool, optional |
| 203 | + load_operators: |
195 | 204 | Whether to automatically load the math operators. The default is ``True``. |
196 | | - use_docker_by_default : bool, optional |
| 205 | + use_docker_by_default: |
197 | 206 | If the environment variable DPF_DOCKER is set to a docker name and use_docker_by_default |
198 | 207 | is True, the server is ran as a docker (default is True). |
199 | | - docker_config : server_factory.DockerConfig, optional |
| 208 | + docker_config: |
200 | 209 | To start DPF server as a docker, specify the docker configuration options here. |
201 | | - timeout : float, optional |
| 210 | + timeout: |
202 | 211 | Maximum number of seconds for the initialization attempt. |
203 | 212 | The default is ``10``. Once the specified number of seconds |
204 | 213 | passes, the connection fails. |
205 | | - config: ServerConfig, optional |
206 | | - Manages the type of server connection to use. |
207 | | - use_pypim_by_default: bool, optional |
| 214 | + config: |
| 215 | + Manages the type of server connection to use. Forced to LegacyGrpc on macOS. |
| 216 | + Defaults to mTLS authenticated gRPC connection. |
| 217 | + Define the path to the mTLS authentication certificates here if needed. |
| 218 | + Define the default server authentication configuration with environment variables: |
| 219 | + - ANSYS_GRPC_CERTIFICATES: path to the certificates directory |
| 220 | + - DPF_GRPC_MODE: gRPC authentication mode, options are 'mtls' and 'insecure'. |
| 221 | + More information available at :ref:`ref_dpf_server_secure_mode`. |
| 222 | + use_pypim_by_default: |
208 | 223 | Whether to use PyPIM functionalities by default when a PyPIM environment is detected. |
209 | 224 | Defaults to True. |
210 | | - context: ServerContext, optional |
| 225 | + context: |
211 | 226 | Defines the settings that will be used to load DPF's plugins. |
212 | 227 | A DPF xml file can be used to list the plugins and set up variables. Default is |
213 | 228 | `server_context.SERVER_CONTEXT`. |
214 | 229 |
|
215 | 230 | Returns |
216 | 231 | ------- |
217 | | - server : server.ServerBase |
| 232 | + server: |
| 233 | + The newly created server. |
218 | 234 | """ |
219 | 235 | from ansys.dpf.core.misc import is_pypim_configured |
220 | 236 |
|
@@ -266,6 +282,8 @@ def start_local_server( |
266 | 282 | if config is not None: |
267 | 283 | grpc_mode = config.grpc_mode |
268 | 284 | certs_dir = config.certificates_dir |
| 285 | + else: |
| 286 | + config = ServerConfig() |
269 | 287 | server = server_type( |
270 | 288 | ansys_path, |
271 | 289 | ip, |
@@ -315,37 +333,49 @@ def start_local_server( |
315 | 333 |
|
316 | 334 |
|
317 | 335 | def connect_to_server( |
318 | | - ip=LOCALHOST, |
319 | | - port=DPF_DEFAULT_PORT, |
320 | | - as_global=True, |
321 | | - timeout=10.0, |
322 | | - config=None, |
323 | | - context=None, |
| 336 | + ip: str = LOCALHOST, |
| 337 | + port: int = DPF_DEFAULT_PORT, |
| 338 | + as_global: bool = True, |
| 339 | + timeout: float = 10.0, |
| 340 | + config: ServerConfig = None, |
| 341 | + context: ServerContext = None, |
324 | 342 | ): |
325 | 343 | """Connect to an existing DPF server. |
326 | 344 |
|
327 | 345 | This method sets the global default channel that is then used for the |
328 | 346 | duration of the DPF session. |
329 | 347 |
|
| 348 | + .. warning:: |
| 349 | + Starting with DPF 2026 R1 and PyDPF 0.15.0, the default gRPC server uses mTLS authentication. |
| 350 | + Please refer to :ref:`ref_dpf_server_secure_mode` for more information on how to set up the |
| 351 | + certificates and configure the server and client accordingly. |
| 352 | + See the ``config`` parameter for more details. |
| 353 | +
|
330 | 354 | Parameters |
331 | 355 | ---------- |
332 | | - ip : str |
| 356 | + ip: |
333 | 357 | IP address of the remote or local instance to connect to. The |
334 | 358 | default is ``"LOCALHOST"``. |
335 | | - port : int |
| 359 | + port: |
336 | 360 | Port to connect to the remote instance on. The default is |
337 | 361 | ``"DPF_DEFAULT_PORT"``, which is 50054. |
338 | | - as_global : bool, optional |
| 362 | + as_global: |
339 | 363 | Global variable that stores the IP address and port for the DPF |
340 | 364 | module. All DPF objects created in this Python session will |
341 | 365 | use this IP and port. The default is ``True``. |
342 | | - timeout : float, optional |
| 366 | + timeout: |
343 | 367 | Maximum number of seconds for the initialization attempt. |
344 | 368 | The default is ``10``. Once the specified number of seconds |
345 | 369 | passes, the connection fails. |
346 | | - config: ServerConfig, optional |
| 370 | + config: |
347 | 371 | Manages the type of server connection to use. Forced to LegacyGrpc on macOS. |
348 | | - context: ServerContext, optional |
| 372 | + Defaults to mTLS authenticated gRPC connection. |
| 373 | + Define the path to the mTLS authentication certificates here if needed. |
| 374 | + Define the default server authentication configuration with environment variables: |
| 375 | + - ANSYS_GRPC_CERTIFICATES: path to the certificates directory |
| 376 | + - DPF_GRPC_MODE: gRPC authentication mode, options are 'mtls' and 'insecure'. |
| 377 | + More information available at :ref:`ref_dpf_server_secure_mode`. |
| 378 | + context: |
349 | 379 | Defines the settings that will be used to load DPF's plugins. |
350 | 380 | A DPF xml file can be used to list the plugins and set up variables. Default is |
351 | 381 | `server_context.SERVER_CONTEXT`. |
|
0 commit comments