about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/azure/ai/ml/entities/_job/service_instance.py
blob: 0e5ba6c6e95cc764c55ce9590ff6a96eaa91f1b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

import logging
from typing import Any, Dict, Optional

from azure.ai.ml._restclient.runhistory.models import ServiceInstanceResult
from azure.ai.ml.entities._mixins import DictMixin, RestTranslatableMixin

module_logger = logging.getLogger(__name__)


class ServiceInstance(RestTranslatableMixin, DictMixin):
    """Service Instance Result.

    :keyword type: The type of service.
    :paramtype type: Optional[str]
    :keyword port: The port used by the service.
    :paramtype port: Optional[int]
    :keyword status: The status of the service.
    :paramtype status: Optional[str]
    :keyword error: The error message.
    :paramtype error: Optional[str]
    :keyword endpoint: The service endpoint.
    :paramtype endpoint: Optional[str]
    :keyword properties: The service instance's properties.
    :paramtype properties: Optional[dict[str, str]]
    """

    def __init__(
        self,  # pylint: disable=unused-argument
        *,
        type: Optional[str] = None,  # pylint: disable=redefined-builtin
        port: Optional[int] = None,
        status: Optional[str] = None,
        error: Optional[str] = None,
        endpoint: Optional[str] = None,
        properties: Optional[Dict[str, str]] = None,
        **kwargs: Any
    ) -> None:
        self.type = type
        self.port = port
        self.status = status
        self.error = error
        self.endpoint = endpoint
        self.properties = properties

    @classmethod
    # pylint: disable=arguments-differ
    def _from_rest_object(cls, obj: ServiceInstanceResult, node_index: int) -> "ServiceInstance":  # type: ignore
        return cls(
            type=obj.type,
            port=obj.port,
            status=obj.status,
            error=obj.error.error.message if obj.error and obj.error.error else None,
            endpoint=obj.endpoint.replace("<nodeIndex>", str(node_index)) if obj.endpoint else obj.endpoint,
            properties=obj.properties,
        )