5
5
# pylint: disable=protected-access
6
6
7
7
from typing import Iterable
8
+ import re
8
9
9
10
from azure .ai .ml .exceptions import ValidationException , ErrorTarget , ErrorCategory , ValidationErrorType
10
- from azure .ai .ml .constants ._common import AzureMLResourceType
11
+ from azure .ai .ml .constants ._common import AzureMLResourceType , REGISTRY_VERSION_PATTERN
11
12
from azure .ai .ml ._telemetry import ActivityType , monitor_with_activity
12
13
from azure .ai .ml ._restclient .v2024_01_01_preview import AzureMachineLearningWorkspaces as ServiceClient202401Preview
13
14
from azure .ai .ml ._restclient .v2024_01_01_preview .models import RegenerateEndpointKeysRequest , KeyType
30
31
31
32
32
33
class ServerlessEndpointOperations (_ScopeDependentOperations ):
34
+ """ServerlessEndpointOperations.
35
+
36
+ You should not instantiate this class directly. Instead, you should
37
+ create an MLClient instance that instantiates it for you and
38
+ attaches it as an attribute.
39
+ """
40
+
33
41
def __init__ (
34
42
self ,
35
43
operation_scope : OperationScope ,
@@ -50,8 +58,29 @@ def _get_workspace_location(self) -> str:
50
58
@experimental
51
59
@monitor_with_activity (ops_logger , "ServerlessEndpoint.BeginCreateOrUpdate" , ActivityType .PUBLICAPI )
52
60
def begin_create_or_update (self , endpoint : ServerlessEndpoint , ** kwargs ) -> LROPoller [ServerlessEndpoint ]:
61
+ """Create or update a serverless endpoint.
62
+
63
+ :param endpoint: The serverless endpoint entity.
64
+ :type endpoint: ~azure.ai.ml.entities.ServerlessEndpoint
65
+ :raises ~azure.ai.ml.exceptions.ValidationException: Raised if ServerlessEndpoint cannot be
66
+ successfully validated. Details will be provided in the error message.
67
+ :return: A poller to track the operation status
68
+ :rtype: ~azure.core.polling.LROPoller[~azure.ai.ml.entities.ServerlessEndpoint]
69
+ """
53
70
if not endpoint .location :
54
71
endpoint .location = self ._get_workspace_location ()
72
+ if re .match (REGISTRY_VERSION_PATTERN , endpoint .model_id ):
73
+ msg = (
74
+ "The given model_id {} points to a specific model version, which is not supported. "
75
+ "Please provide a model_id without the version information."
76
+ )
77
+ raise ValidationException (
78
+ message = msg .format (endpoint .model_id ),
79
+ no_personal_data_message = "Invalid model_id given for serverless endpoint" ,
80
+ target = ErrorTarget .SERVERLESS_ENDPOINT ,
81
+ error_category = ErrorCategory .USER_ERROR ,
82
+ error_type = ValidationErrorType .INVALID_VALUE ,
83
+ )
55
84
return self ._service_client .begin_create_or_update (
56
85
self ._resource_group_name ,
57
86
self ._workspace_name ,
@@ -64,6 +93,13 @@ def begin_create_or_update(self, endpoint: ServerlessEndpoint, **kwargs) -> LROP
64
93
@experimental
65
94
@monitor_with_activity (ops_logger , "ServerlessEndpoint.Get" , ActivityType .PUBLICAPI )
66
95
def get (self , name : str , ** kwargs ) -> ServerlessEndpoint :
96
+ """Get a Serverless Endpoint resource.
97
+
98
+ :param name: Name of the serverless endpoint.
99
+ :type name: str
100
+ :return: Serverless endpoint object retrieved from the service.
101
+ :rtype: ~azure.ai.ml.entities.ServerlessEndpoint
102
+ """
67
103
return self ._service_client .get (
68
104
self ._resource_group_name ,
69
105
self ._workspace_name ,
@@ -75,6 +111,11 @@ def get(self, name: str, **kwargs) -> ServerlessEndpoint:
75
111
@experimental
76
112
@monitor_with_activity (ops_logger , "ServerlessEndpoint.list" , ActivityType .PUBLICAPI )
77
113
def list (self , ** kwargs ) -> Iterable [ServerlessEndpoint ]:
114
+ """List serverless endpoints of the workspace.
115
+
116
+ :return: A list of serverless endpoints
117
+ :rtype: ~typing.Iterable[~azure.ai.ml.entities.ServerlessEndpoint]
118
+ """
78
119
return self ._service_client .list (
79
120
self ._resource_group_name ,
80
121
self ._workspace_name ,
@@ -85,6 +126,13 @@ def list(self, **kwargs) -> Iterable[ServerlessEndpoint]:
85
126
@experimental
86
127
@monitor_with_activity (ops_logger , "ServerlessEndpoint.BeginDelete" , ActivityType .PUBLICAPI )
87
128
def begin_delete (self , name : str , ** kwargs ) -> LROPoller [None ]:
129
+ """Delete a Serverless Endpoint.
130
+
131
+ :param name: Name of the serverless endpoint.
132
+ :type name: str
133
+ :return: A poller to track the operation status.
134
+ :rtype: ~azure.core.polling.LROPoller[None]
135
+ """
88
136
return self ._service_client .begin_delete (
89
137
self ._resource_group_name ,
90
138
self ._workspace_name ,
@@ -95,6 +143,13 @@ def begin_delete(self, name: str, **kwargs) -> LROPoller[None]:
95
143
@experimental
96
144
@monitor_with_activity (ops_logger , "ServerlessEndpoint.GetKeys" , ActivityType .PUBLICAPI )
97
145
def get_keys (self , name : str , ** kwargs ) -> EndpointAuthKeys :
146
+ """Get serveless endpoint auth keys.
147
+
148
+ :param name: The serverless endpoint name
149
+ :type name: str
150
+ :return: Returns the keys of the serverless endpoint
151
+ :rtype: ~azure.ai.ml.entities.EndpointAuthKeys
152
+ """
98
153
return self ._service_client .list_keys (
99
154
self ._resource_group_name ,
100
155
self ._workspace_name ,
@@ -111,7 +166,18 @@ def begin_regenerate_keys(
111
166
* ,
112
167
key_type : str = EndpointKeyType .PRIMARY_KEY_TYPE ,
113
168
** kwargs ,
114
- ) -> LROPoller [None ]:
169
+ ) -> LROPoller [EndpointAuthKeys ]:
170
+ """Regenerate keys for a serverless endpoint.
171
+
172
+ :param name: The endpoint name.
173
+ :type name: str
174
+ :keyword key_type: One of "primary", "secondary". Defaults to "primary".
175
+ :paramtype key_type: str
176
+ :raises ~azure.ai.ml.exceptions.ValidationException: Raised if key_type is not "primary"
177
+ or "secondary"
178
+ :return: A poller to track the operation status.
179
+ :rtype: ~azure.core.polling.LROPoller[EndpointAuthKeys]
180
+ """
115
181
keys = self .get_keys (
116
182
name = name ,
117
183
)
0 commit comments