Skip to content

Commit 9f35533

Browse files
kshitij-microsoftachauhan-sccJayesh Tanna
authored
Feature - deployment templates (#43145) (#43631)
* Deployment Templates API swagger 2024-04-01-dataplanepreview * Kshitij microsoft (#42351) * testing * api review comment for kwargs in job entity * remove unuse entry in change log * adding 2024-04 data plane --------- * Kshitij microsoft (#42477) * testing * api review comment for kwargs in job entity * remove unuse entry in change log * Deployment Templates API swagger 2024-04-01-dataplanepreview * adding 2024-04 data plane * regenerating rest client --------- * Deployment Template complete feature * Adding dataplane clients (#43358) * changes in DT SDK according to new restclient * unit tests fix * sample update * small fixes * fix dict * removing PII * adding absolute import in conftest * removing absolute import in conftest * removing extra init from tests * correcting path in conftest * adding experimental tag, fixing pylint/mypy * removing example * removing example * mypy and pylint pass * mypy and pylint pass * mypy and pylint pass * add remaining experimental tags --------- Co-authored-by: Amit Chauhan <[email protected]> Co-authored-by: Jayesh Tanna <[email protected]>
1 parent 6528ec4 commit 9f35533

File tree

58 files changed

+9797
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+9797
-36
lines changed

sdk/ml/azure-ai-ml/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
### Features Added
66

77
- Removed the dependencies - msrest and six
8+
- Added support for `Deployment Templates` along with the following operations:
9+
- `ml_client.deployment_templates.create_or_update()`
10+
- `ml_client.deployment_templates.list()`
11+
- `ml_client.deployment_templates.get()`
12+
- `ml_client.deployment_templates.archive()`
13+
- `ml_client.deployment_templates.restore()`
814

915
### Bugs Fixed
1016
- Fix for registry resource group passed to OnlineEndpointOperations when model is in registry in different resource group compared to workspace.

sdk/ml/azure-ai-ml/azure/ai/ml/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
load_connection,
3030
load_data,
3131
load_datastore,
32+
load_deployment_template,
3233
load_environment,
3334
load_feature_set,
3435
load_feature_store,
@@ -67,6 +68,7 @@
6768
"load_compute",
6869
"load_data",
6970
"load_datastore",
71+
"load_deployment_template",
7072
"load_feature_set",
7173
"load_feature_store",
7274
"load_feature_store_entity",

sdk/ml/azure-ai-ml/azure/ai/ml/_ml_client.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@
3939
from azure.ai.ml._restclient.v2024_01_01_preview import AzureMachineLearningWorkspaces as ServiceClient012024Preview
4040
from azure.ai.ml._restclient.v2024_04_01_preview import AzureMachineLearningWorkspaces as ServiceClient042024Preview
4141
from azure.ai.ml._restclient.v2024_07_01_preview import AzureMachineLearningWorkspaces as ServiceClient072024Preview
42-
from azure.ai.ml._restclient.v2024_10_01_preview import AzureMachineLearningWorkspaces as ServiceClient102024Preview
43-
from azure.ai.ml._restclient.v2025_01_01_preview import AzureMachineLearningWorkspaces as ServiceClient012025Preview
42+
from azure.ai.ml._restclient.v2024_10_01_preview import (
43+
AzureMachineLearningWorkspaces as ServiceClient102024Preview,
44+
)
45+
from azure.ai.ml._restclient.v2025_01_01_preview import (
46+
AzureMachineLearningWorkspaces as ServiceClient012025Preview,
47+
)
48+
from azure.ai.ml._restclient.v2024_04_01_dataplanepreview import (
49+
AzureMachineLearningWorkspaces as ServiceClient042024DataPlanePreview,
50+
)
4451
from azure.ai.ml._restclient.workspace_dataplane import (
4552
AzureMachineLearningWorkspaces as ServiceClientWorkspaceDataplane,
4653
)
@@ -59,6 +66,7 @@
5966
Component,
6067
Compute,
6168
Datastore,
69+
DeploymentTemplate,
6270
Environment,
6371
Index,
6472
Job,
@@ -84,6 +92,7 @@
8492
ComputeOperations,
8593
DataOperations,
8694
DatastoreOperations,
95+
DeploymentTemplateOperations,
8796
EnvironmentOperations,
8897
EvaluatorOperations,
8998
IndexOperations,
@@ -377,6 +386,13 @@ def __init__(
377386
**kwargs,
378387
)
379388

389+
self._service_client_04_2024_dataplanepreview = ServiceClient042024DataPlanePreview(
390+
credential=self._credential,
391+
subscription_id=self._operation_scope._subscription_id,
392+
base_url=base_url,
393+
**kwargs,
394+
)
395+
380396
self._service_client_07_2024_preview = ServiceClient072024Preview(
381397
credential=self._credential,
382398
subscription_id=(
@@ -668,6 +684,14 @@ def __init__(
668684
)
669685
self._operation_container.add(AzureMLResourceType.ONLINE_DEPLOYMENT, self._online_deployments)
670686
self._operation_container.add(AzureMLResourceType.BATCH_DEPLOYMENT, self._batch_deployments)
687+
688+
self._deployment_templates = DeploymentTemplateOperations(
689+
self._operation_scope,
690+
self._operation_config,
691+
self._service_client_04_2024_dataplanepreview,
692+
**ops_kwargs,
693+
)
694+
671695
self._data = DataOperations(
672696
self._ws_operation_scope if registry_reference else self._operation_scope,
673697
self._operation_config,
@@ -1074,6 +1098,16 @@ def batch_deployments(self) -> BatchDeploymentOperations:
10741098
"""
10751099
return self._batch_deployments
10761100

1101+
@property
1102+
@experimental
1103+
def deployment_templates(self) -> DeploymentTemplateOperations:
1104+
"""A collection of deployment template related operations.
1105+
1106+
:return: Deployment Template operations.
1107+
:rtype: ~azure.ai.ml.operations.DeploymentTemplateOperations
1108+
"""
1109+
return self._deployment_templates
1110+
10771111
@property
10781112
def datastores(self) -> DatastoreOperations:
10791113
"""A collection of datastore related operations.
@@ -1454,3 +1488,10 @@ def _(entity: ServerlessEndpoint, operations, *args, **kwargs):
14541488
def _(entity: MarketplaceSubscription, operations, *args, **kwargs):
14551489
module_logger.debug("Creating or updating marketplace subscriptions")
14561490
return operations[AzureMLResourceType.MARKETPLACE_SUBSCRIPTION].begin_create_or_update(entity, **kwargs)
1491+
1492+
1493+
@_begin_create_or_update.register(DeploymentTemplate)
1494+
def _(entity: DeploymentTemplate, operations, *args, **kwargs):
1495+
module_logger.debug("Creating or updating capability hosts")
1496+
1497+
return operations[AzureMLResourceType.DEPLOYMENT_TEMPLATE].begin_create_or_update(entity, **kwargs)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from ._azure_machine_learning_workspaces import AzureMachineLearningWorkspaces
10+
from ._version import VERSION
11+
12+
__version__ = VERSION
13+
__all__ = ['AzureMachineLearningWorkspaces']
14+
15+
# `._patch.py` is used for handwritten extensions to the generated code
16+
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
17+
from ._patch import patch_sdk
18+
patch_sdk()
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from copy import deepcopy
10+
from typing import TYPE_CHECKING
11+
12+
from msrest import Deserializer, Serializer
13+
14+
from azure.mgmt.core import ARMPipelineClient
15+
16+
from . import models
17+
from ._configuration import AzureMachineLearningWorkspacesConfiguration
18+
from .operations import DeploymentTemplatesOperations, IndexesOperations
19+
20+
if TYPE_CHECKING:
21+
# pylint: disable=unused-import,ungrouped-imports
22+
from typing import Any
23+
24+
from azure.core.credentials import TokenCredential
25+
from azure.core.rest import HttpRequest, HttpResponse
26+
27+
class AzureMachineLearningWorkspaces(object):
28+
"""AzureMachineLearningWorkspaces.
29+
30+
:ivar deployment_templates: DeploymentTemplatesOperations operations
31+
:vartype deployment_templates:
32+
azure.mgmt.machinelearningservices.operations.DeploymentTemplatesOperations
33+
:ivar indexes: IndexesOperations operations
34+
:vartype indexes: azure.mgmt.machinelearningservices.operations.IndexesOperations
35+
:param credential: Credential needed for the client to connect to Azure.
36+
:type credential: ~azure.core.credentials.TokenCredential
37+
:keyword api_version: Api Version. The default value is "2024-04-01-preview". Note that
38+
overriding this default value may result in unsupported behavior.
39+
:paramtype api_version: str
40+
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
41+
Retry-After header is present.
42+
"""
43+
44+
def __init__(
45+
self,
46+
credential, # type: "TokenCredential"
47+
**kwargs # type: Any
48+
):
49+
# type: (...) -> None
50+
_base_url = '{endpoint}/genericasset/v2.0/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices'
51+
self._config = AzureMachineLearningWorkspacesConfiguration(credential=credential, **kwargs)
52+
# Remove base_url from kwargs to avoid conflict, then pass as positional argument
53+
kwargs_copy = kwargs.copy()
54+
kwargs_copy.pop('base_url', None)
55+
self._client = ARMPipelineClient(_base_url, config=self._config, **kwargs_copy)
56+
57+
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
58+
self._serialize = Serializer(client_models)
59+
self._deserialize = Deserializer(client_models)
60+
self._serialize.client_side_validation = False
61+
self.deployment_templates = DeploymentTemplatesOperations(self._client, self._config, self._serialize, self._deserialize)
62+
self.indexes = IndexesOperations(self._client, self._config, self._serialize, self._deserialize)
63+
64+
65+
def _send_request(
66+
self,
67+
request, # type: HttpRequest
68+
**kwargs # type: Any
69+
):
70+
# type: (...) -> HttpResponse
71+
"""Runs the network request through the client's chained policies.
72+
73+
>>> from azure.core.rest import HttpRequest
74+
>>> request = HttpRequest("GET", "https://www.example.org/")
75+
<HttpRequest [GET], url: 'https://www.example.org/'>
76+
>>> response = client._send_request(request)
77+
<HttpResponse: 200 OK>
78+
79+
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart
80+
81+
:param request: The network request you want to make. Required.
82+
:type request: ~azure.core.rest.HttpRequest
83+
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
84+
:return: The response of your network call. Does not do error handling on your response.
85+
:rtype: ~azure.core.rest.HttpResponse
86+
"""
87+
88+
request_copy = deepcopy(request)
89+
request_copy.url = self._client.format_url(request_copy.url)
90+
return self._client.send_request(request_copy, **kwargs)
91+
92+
def close(self):
93+
# type: () -> None
94+
self._client.close()
95+
96+
def __enter__(self):
97+
# type: () -> AzureMachineLearningWorkspaces
98+
self._client.__enter__()
99+
return self
100+
101+
def __exit__(self, *exc_details):
102+
# type: (Any) -> None
103+
self._client.__exit__(*exc_details)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
from typing import TYPE_CHECKING
10+
11+
from azure.core.configuration import Configuration
12+
from azure.core.pipeline import policies
13+
from azure.mgmt.core.policies import ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy
14+
15+
from ._version import VERSION
16+
17+
if TYPE_CHECKING:
18+
# pylint: disable=unused-import,ungrouped-imports
19+
from typing import Any
20+
21+
from azure.core.credentials import TokenCredential
22+
23+
24+
class AzureMachineLearningWorkspacesConfiguration(Configuration): # pylint: disable=too-many-instance-attributes
25+
"""Configuration for AzureMachineLearningWorkspaces.
26+
27+
Note that all parameters used to create this instance are saved as instance
28+
attributes.
29+
30+
:param credential: Credential needed for the client to connect to Azure.
31+
:type credential: ~azure.core.credentials.TokenCredential
32+
:keyword api_version: Api Version. The default value is "2024-04-01-preview". Note that
33+
overriding this default value may result in unsupported behavior.
34+
:paramtype api_version: str
35+
"""
36+
37+
def __init__(
38+
self,
39+
credential, # type: "TokenCredential"
40+
**kwargs # type: Any
41+
):
42+
# type: (...) -> None
43+
super(AzureMachineLearningWorkspacesConfiguration, self).__init__(**kwargs)
44+
api_version = kwargs.pop('api_version', "2024-04-01-preview") # type: str
45+
46+
if credential is None:
47+
raise ValueError("Parameter 'credential' must not be None.")
48+
49+
self.credential = credential
50+
self.api_version = api_version
51+
self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default'])
52+
kwargs.setdefault('sdk_moniker', 'mgmt-machinelearningservices/{}'.format(VERSION))
53+
self._configure(**kwargs)
54+
55+
def _configure(
56+
self,
57+
**kwargs # type: Any
58+
):
59+
# type: (...) -> None
60+
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs)
61+
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs)
62+
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs)
63+
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs)
64+
self.http_logging_policy = kwargs.get('http_logging_policy') or ARMHttpLoggingPolicy(**kwargs)
65+
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs)
66+
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs)
67+
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs)
68+
self.authentication_policy = kwargs.get('authentication_policy')
69+
if self.credential and not self.authentication_policy:
70+
self.authentication_policy = ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
#
4+
# Copyright (c) Microsoft Corporation. All rights reserved.
5+
#
6+
# The MIT License (MIT)
7+
#
8+
# Permission is hereby granted, free of charge, to any person obtaining a copy
9+
# of this software and associated documentation files (the ""Software""), to
10+
# deal in the Software without restriction, including without limitation the
11+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
# sell copies of the Software, and to permit persons to whom the Software is
13+
# furnished to do so, subject to the following conditions:
14+
#
15+
# The above copyright notice and this permission notice shall be included in
16+
# all copies or substantial portions of the Software.
17+
#
18+
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24+
# IN THE SOFTWARE.
25+
#
26+
# --------------------------------------------------------------------------
27+
28+
# This file is used for handwritten extensions to the generated code. Example:
29+
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
30+
def patch_sdk():
31+
pass
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# --------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# Code generated by Microsoft (R) AutoRest Code Generator.
5+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
6+
# --------------------------------------------------------------------------
7+
8+
from azure.core.pipeline.transport import HttpRequest
9+
10+
def _convert_request(request, files=None):
11+
data = request.content if not files else None
12+
request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data)
13+
if files:
14+
request.set_formdata_body(files)
15+
return request
16+
17+
def _format_url_section(template, **kwargs):
18+
components = template.split("/")
19+
while components:
20+
try:
21+
return template.format(**kwargs)
22+
except KeyError as key:
23+
formatted_components = template.split("/")
24+
components = [
25+
c for c in formatted_components if "{}".format(key.args[0]) not in c
26+
]
27+
template = "/".join(components)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# coding=utf-8
2+
# --------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See License.txt in the project root for license information.
5+
# Code generated by Microsoft (R) AutoRest Code Generator.
6+
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
# --------------------------------------------------------------------------
8+
9+
VERSION = "0.1.0"

0 commit comments

Comments
 (0)