create_instance#

Client.create_instance(product_name: str, product_version: str | None = None, requests_timeout: float | None = None, security_settings: InsecureSettings | MtlsSettings | WnuaSettings | UdsSettings | None = None) Instance#

Create a remote instance of a product based on its name and optionally its version.

This effectively starts the product in the backend, according to the backend configuration.

The created instance will not yet be ready to use. You must call wait_for_ready() to wait for the instance to be ready.

Parameters:
product_namestr

Name of the product to start. For example, mapdl.

product_versionstr, optional

Version of the product. For example, "222". The default is None.

requests_timeoutfloat, optional

Maximum time for each request in seconds. The default is None.

security_settingsSecuritySettings, optional

Transport security settings for the instance. One of InsecureSettings, MtlsSettings, WnuaSettings, or UdsSettings. The default is None (server default). This is a request: the transport the instance actually uses is reported back through each of its services. See Security.

Returns:
Instance

Instance of the product.

Raises:
UnsupportedProductError

The product or the selected version is not available remotely.

Examples

Create an instance with default security settings:

>>> import ansys.platform.instancemanagement as pypim
>>> client = pypim.connect()
>>> instance = client.create_instance(product_name="mapdl")
>>> instance.wait_for_ready()
>>> print(instance.services)
>>> instance.delete()
    {'grpc': Service(uri='dns:10.240.4.231:50052', headers={}, security=None)}

Create an instance using UDS (Unix Domain Socket) security settings:

>>> import ansys.platform.instancemanagement as pypim
>>> from ansys.platform.instancemanagement import UdsSettings
>>> client = pypim.connect()
>>> instance = client.create_instance(
...     product_name="mapdl",
...     security_settings=UdsSettings(),
... )
>>> instance.wait_for_ready()
>>> print(instance.services)
>>> instance.delete()
    {
        'grpc': Service(
            uri='unix:/home/jdoe/.conn/mapdl.sock',
            headers={},
            security=ServiceSecurity(transport='uds', cert_files=None),
        )
    }

Create an instance using mTLS security settings:

>>> import ansys.platform.instancemanagement as pypim
>>> from ansys.platform.instancemanagement import MtlsSettings
>>> client = pypim.connect()
>>> mtls = MtlsSettings(
...     certificates_directory="/path/to/certs",
... )
>>> instance = client.create_instance(
...     product_name="mapdl",
...     security_settings=mtls,
... )
>>> instance.wait_for_ready()
>>> print(instance.services)
>>> instance.delete()
    {
        'grpc': Service(
            uri='dns:127.0.0.1:63006',
            headers={},
            security=ServiceSecurity(transport='mtls',
                cert_files=CertificateFiles(
                    cert_file='/path/to/certs/client.crt',
                    key_file='/path/to/certs/client.key',
                    ca_file='path/to/certs/ca.crt')
                )
            )
    }