|
12 | 12 | from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error
|
13 | 13 | from azure.core.pipeline import PipelineResponse
|
14 | 14 | from azure.core.pipeline.transport import HttpResponse
|
| 15 | +from azure.core.polling import LROPoller, NoPolling |
15 | 16 | from azure.core.rest import HttpRequest
|
16 | 17 | from azure.core.tracing.decorator import distributed_trace
|
17 | 18 | from azure.mgmt.core.exceptions import ARMErrorFormat
|
| 19 | +from azure.mgmt.core.polling.arm_polling import ARMPolling |
18 | 20 | from msrest import Serializer
|
19 | 21 |
|
20 | 22 | from .. import models as _models
|
@@ -457,6 +459,50 @@ def build_deployment_settings_request(
|
457 | 459 | **kwargs
|
458 | 460 | )
|
459 | 461 |
|
| 462 | + |
| 463 | +def build_create_or_update_request_initial( |
| 464 | + name, # type: str |
| 465 | + version, # type: str |
| 466 | + subscription_id, # type: str |
| 467 | + resource_group_name, # type: str |
| 468 | + registry_name, # type: str |
| 469 | + **kwargs # type: Any |
| 470 | +): |
| 471 | + # type: (...) -> HttpRequest |
| 472 | + api_version = kwargs.pop('api_version', "2021-10-01-dataplanepreview") # type: str |
| 473 | + content_type = kwargs.pop('content_type', None) # type: Optional[str] |
| 474 | + |
| 475 | + accept = "application/json" |
| 476 | + # Construct URL |
| 477 | + url = kwargs.pop("template_url", '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/registries/{registryName}/models/{name}/versions/{version}') |
| 478 | + path_format_arguments = { |
| 479 | + "name": _SERIALIZER.url("name", name, 'str', pattern=r'^(?![\-_.])[a-zA-Z0-9\-_.]{1,255}(?<!\.)$'), |
| 480 | + "version": _SERIALIZER.url("version", version, 'str'), |
| 481 | + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), |
| 482 | + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), |
| 483 | + "registryName": _SERIALIZER.url("registry_name", registry_name, 'str'), |
| 484 | + } |
| 485 | + |
| 486 | + url = _format_url_section(url, **path_format_arguments) |
| 487 | + |
| 488 | + # Construct parameters |
| 489 | + query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] |
| 490 | + query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') |
| 491 | + |
| 492 | + # Construct headers |
| 493 | + header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] |
| 494 | + if content_type is not None: |
| 495 | + header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') |
| 496 | + header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') |
| 497 | + |
| 498 | + return HttpRequest( |
| 499 | + method="PUT", |
| 500 | + url=url, |
| 501 | + params=query_parameters, |
| 502 | + headers=header_parameters, |
| 503 | + **kwargs |
| 504 | + ) |
| 505 | + |
460 | 506 | # fmt: on
|
461 | 507 | class ModelsOperations(object):
|
462 | 508 | """ModelsOperations operations.
|
@@ -825,6 +871,107 @@ def create_unregistered_output_model(
|
825 | 871 | create_unregistered_output_model.metadata = {'url': '/modelregistry/v1.0/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/models/createUnregisteredOutput'} # type: ignore
|
826 | 872 |
|
827 | 873 |
|
| 874 | + # this method is only used for model create/update with system metadata |
| 875 | + @distributed_trace |
| 876 | + def begin_create_or_update_model_with_system_metadata( |
| 877 | + self, |
| 878 | + subscription_id, # type: str |
| 879 | + name, # type: str |
| 880 | + version, # type: str |
| 881 | + resource_group_name, # type: str |
| 882 | + registry_name, # type: str |
| 883 | + body, # type: "ModelVersion" |
| 884 | + **kwargs, # type: Any |
| 885 | + ): |
| 886 | + # type: (...) -> LROPoller[None] |
| 887 | + """Create or update version. |
| 888 | +
|
| 889 | + Create or update version. |
| 890 | +
|
| 891 | + :param name: Container name. |
| 892 | + :type name: str |
| 893 | + :param version: Version identifier. |
| 894 | + :type version: str |
| 895 | + :param resource_group_name: The name of the resource group. The name is case insensitive. |
| 896 | + :type resource_group_name: str |
| 897 | + :param registry_name: Name of Azure Machine Learning registry. |
| 898 | + :type registry_name: str |
| 899 | + :param body: Version entity to create or update. |
| 900 | + :type body: ~azure.mgmt.machinelearningservices.models.ModelVersionData |
| 901 | + :keyword api_version: Api Version. The default value is "2021-10-01-dataplanepreview". Note |
| 902 | + that overriding this default value may result in unsupported behavior. |
| 903 | + :paramtype api_version: str |
| 904 | + :keyword callable cls: A custom type or function that will be passed the direct response |
| 905 | + :keyword str continuation_token: A continuation token to restart a poller from a saved state. |
| 906 | + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this |
| 907 | + operation to not poll, or pass in your own initialized polling object for a personal polling |
| 908 | + strategy. |
| 909 | + :paramtype polling: bool or ~azure.core.polling.PollingMethod |
| 910 | + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no |
| 911 | + Retry-After header is present. |
| 912 | + :return: An instance of LROPoller that returns either None or the result of cls(response) |
| 913 | + :rtype: ~azure.core.polling.LROPoller[None] |
| 914 | + :raises: ~azure.core.exceptions.HttpResponseError |
| 915 | + """ |
| 916 | + |
| 917 | + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} |
| 918 | + error_map.update(kwargs.pop("error_map", {})) |
| 919 | + |
| 920 | + _json = self._serialize.body(body, "ModelVersionData") |
| 921 | + _json["properties"]["system_metadata"] = body.properties.system_metadata |
| 922 | + |
| 923 | + request = build_create_or_update_request_initial( |
| 924 | + name=name, |
| 925 | + version=version, |
| 926 | + subscription_id=subscription_id, |
| 927 | + resource_group_name=resource_group_name, |
| 928 | + registry_name=registry_name, |
| 929 | + json=_json, |
| 930 | + template_url=self.begin_create_or_update_model_with_system_metadata.metadata["url"], |
| 931 | + ) |
| 932 | + request = _convert_request(request) |
| 933 | + request.url = self._client.format_url(request.url) |
| 934 | + |
| 935 | + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) |
| 936 | + response = pipeline_response.http_response |
| 937 | + |
| 938 | + if response.status_code not in [202]: |
| 939 | + map_error(status_code=response.status_code, response=response, error_map=error_map) |
| 940 | + raise HttpResponseError(response=response, error_format=ARMErrorFormat) |
| 941 | + |
| 942 | + response_headers = {} |
| 943 | + response_headers["x-ms-async-operation-timeout"] = self._deserialize( |
| 944 | + "duration", response.headers.get("x-ms-async-operation-timeout") |
| 945 | + ) |
| 946 | + response_headers["Location"] = self._deserialize( |
| 947 | + "str", response.headers.get("Location") |
| 948 | + ) |
| 949 | + response_headers["Retry-After"] = self._deserialize( |
| 950 | + "int", response.headers.get("Retry-After") |
| 951 | + ) |
| 952 | + |
| 953 | + cls = kwargs.pop("cls", None) |
| 954 | + |
| 955 | + def get_long_running_output(pipeline_response): |
| 956 | + if cls: |
| 957 | + return cls(pipeline_response, None, {}) |
| 958 | + return None |
| 959 | + |
| 960 | + polling = kwargs.pop("polling", True) |
| 961 | + if polling is True: |
| 962 | + lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) |
| 963 | + polling_method = ARMPolling(lro_delay, **kwargs) |
| 964 | + elif polling is False: |
| 965 | + polling_method = NoPolling() |
| 966 | + else: |
| 967 | + polling_method = polling |
| 968 | + |
| 969 | + return LROPoller( |
| 970 | + self._client, pipeline_response, get_long_running_output, polling_method |
| 971 | + ) |
| 972 | + |
| 973 | + begin_create_or_update_model_with_system_metadata.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/registries/{registryName}/models/{name}/versions/{version}"} # type: ignore |
| 974 | + |
828 | 975 | @distributed_trace
|
829 | 976 | def batch_get_resolved_uris(
|
830 | 977 | self,
|
|
0 commit comments