From c29ac0837fce7fcb48acaf805aac68173239fb75 Mon Sep 17 00:00:00 2001 From: SDKAuto Date: Fri, 18 Feb 2022 09:18:21 +0000 Subject: [PATCH] CodeGen from PR 17827 in Azure/azure-rest-api-specs Merge 6298506a310492065a6a2db33e5f34b7515800fd into 0229905ebb1e140b68ce2f4b90ef185dea0f79ad --- .../azure-mgmt-workloadmonitor/_meta.json | 11 + .../azure/mgmt/workloadmonitor/__init__.py | 9 +- .../mgmt/workloadmonitor/_configuration.py | 17 +- .../azure/mgmt/workloadmonitor/_metadata.json | 74 ++- .../azure/mgmt/workloadmonitor/_patch.py | 31 + .../azure/mgmt/workloadmonitor/_vendor.py | 27 + .../azure/mgmt/workloadmonitor/_version.py | 2 +- .../workloadmonitor/_workload_monitor_api.py | 67 ++- .../mgmt/workloadmonitor/aio/__init__.py | 5 + .../workloadmonitor/aio/_configuration.py | 6 +- .../azure/mgmt/workloadmonitor/aio/_patch.py | 31 + .../aio/_workload_monitor_api.py | 58 +- .../operations/_health_monitors_operations.py | 284 ++++----- .../aio/operations/_monitors_operations.py | 421 ------------- .../aio/operations/_operations.py | 54 +- .../mgmt/workloadmonitor/models/__init__.py | 36 +- .../mgmt/workloadmonitor/models/_models.py | 416 ------------- .../workloadmonitor/models/_models_py3.py | 248 +++++--- .../models/_workload_monitor_api_enums.py | 21 +- .../operations/_health_monitors_operations.py | 554 ++++++++++++------ .../operations/_monitors_operations.py | 429 -------------- .../workloadmonitor/operations/_operations.py | 93 +-- 22 files changed, 1050 insertions(+), 1844 deletions(-) create mode 100644 sdk/workloadmonitor/azure-mgmt-workloadmonitor/_meta.json create mode 100644 sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_patch.py create mode 100644 sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_vendor.py create mode 100644 sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_patch.py delete mode 100644 sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_monitors_operations.py delete mode 100644 sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_models.py delete mode 100644 sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_monitors_operations.py diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/_meta.json b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/_meta.json new file mode 100644 index 000000000000..cd974f7a4b44 --- /dev/null +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/_meta.json @@ -0,0 +1,11 @@ +{ + "autorest": "3.7.2", + "use": [ + "@autorest/python@5.12.0", + "@autorest/modelerfour@4.19.3" + ], + "commit": "46ad97970c9c2050396de6d1d0f586166b8d0417", + "repository_url": "https://github.com/Azure/azure-rest-api-specs", + "autorest_command": "autorest specification/workloadmonitor/resource-manager/readme.md --multiapi --python --python-mode=update --python-sdks-folder=/home/vsts/work/1/s/azure-sdk-for-python/sdk --python3-only --track2 --use=@autorest/python@5.12.0 --use=@autorest/modelerfour@4.19.3 --version=3.7.2", + "readme": "specification/workloadmonitor/resource-manager/readme.md" +} \ No newline at end of file diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/__init__.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/__init__.py index c37af49459bf..0bc8fc5b3616 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/__init__.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/__init__.py @@ -12,8 +12,7 @@ __version__ = VERSION __all__ = ['WorkloadMonitorAPI'] -try: - from ._patch import patch_sdk # type: ignore - patch_sdk() -except ImportError: - pass +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk +patch_sdk() diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_configuration.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_configuration.py index d279275d4bd0..514270ced27f 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_configuration.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_configuration.py @@ -6,18 +6,16 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import TYPE_CHECKING +from typing import Any, TYPE_CHECKING from azure.core.configuration import Configuration from azure.core.pipeline import policies -from azure.mgmt.core.policies import ARMHttpLoggingPolicy +from azure.mgmt.core.policies import ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy from ._version import VERSION if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any - from azure.core.credentials import TokenCredential @@ -33,13 +31,12 @@ class WorkloadMonitorAPIConfiguration(Configuration): def __init__( self, - credential, # type: "TokenCredential" - **kwargs # type: Any - ): - # type: (...) -> None + credential: "TokenCredential", + **kwargs: Any + ) -> None: + super(WorkloadMonitorAPIConfiguration, self).__init__(**kwargs) if credential is None: raise ValueError("Parameter 'credential' must not be None.") - super(WorkloadMonitorAPIConfiguration, self).__init__(**kwargs) self.credential = credential self.api_version = "2020-01-13-preview" @@ -62,4 +59,4 @@ def _configure( self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs) self.authentication_policy = kwargs.get('authentication_policy') if self.credential and not self.authentication_policy: - self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs) + self.authentication_policy = ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs) diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_metadata.json b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_metadata.json index bfd25751f9c4..4f33419f4ffc 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_metadata.json +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_metadata.json @@ -5,23 +5,26 @@ "name": "WorkloadMonitorAPI", "filename": "_workload_monitor_api", "description": "Workload Monitor API.", - "base_url": "\u0027https://management.azure.com\u0027", - "custom_base_url": null, + "host_value": "\"https://management.azure.com\"", + "parameterized_host_template": null, "azure_arm": true, - "has_lro_operations": false + "has_lro_operations": false, + "client_side_validation": false, + "sync_imports": "{\"typing\": {\"azurecore\": {\"azure.core.credentials\": [\"TokenCredential\"]}}, \"regular\": {\"azurecore\": {\"azure.profiles\": [\"KnownProfiles\", \"ProfileDefinition\"], \"azure.profiles.multiapiclient\": [\"MultiApiClientMixin\"], \"msrest\": [\"Deserializer\", \"Serializer\"], \"azure.mgmt.core\": [\"ARMPipelineClient\"]}, \"local\": {\"._configuration\": [\"WorkloadMonitorAPIConfiguration\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Optional\"]}}}", + "async_imports": "{\"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"], \"azure.core.credentials\": [\"TokenCredential\"]}}, \"regular\": {\"azurecore\": {\"azure.profiles\": [\"KnownProfiles\", \"ProfileDefinition\"], \"azure.profiles.multiapiclient\": [\"MultiApiClientMixin\"], \"msrest\": [\"Deserializer\", \"Serializer\"], \"azure.mgmt.core\": [\"AsyncARMPipelineClient\"]}, \"local\": {\"._configuration\": [\"WorkloadMonitorAPIConfiguration\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\", \"Optional\"]}}}" }, "global_parameters": { - "sync_method": { + "sync": { "credential": { - "method_signature": "credential, # type: \"TokenCredential\"", + "signature": "credential, # type: \"TokenCredential\"", "description": "Credential needed for the client to connect to Azure.", "docstring_type": "~azure.core.credentials.TokenCredential", "required": true } }, - "async_method": { + "async": { "credential": { - "method_signature": "credential, # type: \"AsyncTokenCredential\"", + "signature": "credential: \"AsyncTokenCredential\",", "description": "Credential needed for the client to connect to Azure.", "docstring_type": "~azure.core.credentials_async.AsyncTokenCredential", "required": true @@ -29,21 +32,60 @@ }, "constant": { }, - "call": "credential" + "call": "credential", + "service_client_specific": { + "sync": { + "api_version": { + "signature": "api_version=None, # type: Optional[str]", + "description": "API version to use if no profile is provided, or if missing in profile.", + "docstring_type": "str", + "required": false + }, + "base_url": { + "signature": "base_url=\"https://management.azure.com\", # type: str", + "description": "Service URL", + "docstring_type": "str", + "required": false + }, + "profile": { + "signature": "profile=KnownProfiles.default, # type: KnownProfiles", + "description": "A profile definition, from KnownProfiles to dict.", + "docstring_type": "azure.profiles.KnownProfiles", + "required": false + } + }, + "async": { + "api_version": { + "signature": "api_version: Optional[str] = None,", + "description": "API version to use if no profile is provided, or if missing in profile.", + "docstring_type": "str", + "required": false + }, + "base_url": { + "signature": "base_url: str = \"https://management.azure.com\",", + "description": "Service URL", + "docstring_type": "str", + "required": false + }, + "profile": { + "signature": "profile: KnownProfiles = KnownProfiles.default,", + "description": "A profile definition, from KnownProfiles to dict.", + "docstring_type": "azure.profiles.KnownProfiles", + "required": false + } + } + } }, "config": { "credential": true, "credential_scopes": ["https://management.azure.com/.default"], - "credential_default_policy_type": "BearerTokenCredentialPolicy", - "credential_default_policy_type_has_async_version": true, - "credential_key_header_name": null + "credential_call_sync": "ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)", + "credential_call_async": "AsyncARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs)", + "sync_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMChallengeAuthenticationPolicy\", \"ARMHttpLoggingPolicy\"]}, \"local\": {\"._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials\": [\"TokenCredential\"]}}}", + "async_imports": "{\"regular\": {\"azurecore\": {\"azure.core.configuration\": [\"Configuration\"], \"azure.core.pipeline\": [\"policies\"], \"azure.mgmt.core.policies\": [\"ARMHttpLoggingPolicy\", \"AsyncARMChallengeAuthenticationPolicy\"]}, \"local\": {\".._version\": [\"VERSION\"]}}, \"conditional\": {\"stdlib\": {\"typing\": [\"Any\"]}}, \"typing\": {\"azurecore\": {\"azure.core.credentials_async\": [\"AsyncTokenCredential\"]}}}" }, "operation_groups": { "operations": "Operations", "health_monitors": "HealthMonitorsOperations" - }, - "operation_mixins": { - }, - "sync_imports": "None", - "async_imports": "None" + } } \ No newline at end of file diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_patch.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_patch.py new file mode 100644 index 000000000000..74e48ecd07cf --- /dev/null +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass \ No newline at end of file diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_vendor.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_vendor.py new file mode 100644 index 000000000000..138f663c53a4 --- /dev/null +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_vendor.py @@ -0,0 +1,27 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.core.pipeline.transport import HttpRequest + +def _convert_request(request, files=None): + data = request.content if not files else None + request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data) + if files: + request.set_formdata_body(files) + return request + +def _format_url_section(template, **kwargs): + components = template.split("/") + while components: + try: + return template.format(**kwargs) + except KeyError as key: + formatted_components = template.split("/") + components = [ + c for c in formatted_components if "{}".format(key.args[0]) not in c + ] + template = "/".join(components) diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_version.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_version.py index dfa6ee022f15..e5754a47ce68 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_version.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "1.0.0b2" +VERSION = "1.0.0b1" diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_workload_monitor_api.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_workload_monitor_api.py index 8c60167ac48d..6fd36c9fdf82 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_workload_monitor_api.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/_workload_monitor_api.py @@ -6,24 +6,22 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import TYPE_CHECKING +from copy import deepcopy +from typing import Any, Optional, TYPE_CHECKING +from azure.core.rest import HttpRequest, HttpResponse from azure.mgmt.core import ARMPipelineClient from msrest import Deserializer, Serializer +from . import models +from ._configuration import WorkloadMonitorAPIConfiguration +from .operations import HealthMonitorsOperations, Operations + if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Optional - from azure.core.credentials import TokenCredential -from ._configuration import WorkloadMonitorAPIConfiguration -from .operations import Operations -from .operations import HealthMonitorsOperations -from . import models - - -class WorkloadMonitorAPI(object): +class WorkloadMonitorAPI: """Workload Monitor API. :ivar operations: Operations operations @@ -32,29 +30,52 @@ class WorkloadMonitorAPI(object): :vartype health_monitors: workload_monitor_api.operations.HealthMonitorsOperations :param credential: Credential needed for the client to connect to Azure. :type credential: ~azure.core.credentials.TokenCredential - :param str base_url: Service URL + :param base_url: Service URL. Default value is 'https://management.azure.com'. + :type base_url: str """ def __init__( self, - credential, # type: "TokenCredential" - base_url=None, # type: Optional[str] - **kwargs # type: Any - ): - # type: (...) -> None - if not base_url: - base_url = 'https://management.azure.com' - self._config = WorkloadMonitorAPIConfiguration(credential, **kwargs) + credential: "TokenCredential", + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + self._config = WorkloadMonitorAPIConfiguration(credential=credential, **kwargs) self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs) client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) + self.health_monitors = HealthMonitorsOperations(self._client, self._config, self._serialize, self._deserialize) + + + def _send_request( + self, + request, # type: HttpRequest + **kwargs: Any + ) -> HttpResponse: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.HttpResponse + """ - self.operations = Operations( - self._client, self._config, self._serialize, self._deserialize) - self.health_monitors = HealthMonitorsOperations( - self._client, self._config, self._serialize, self._deserialize) + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) def close(self): # type: () -> None diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/__init__.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/__init__.py index a02775a1a951..9d307fa6b6ea 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/__init__.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/__init__.py @@ -8,3 +8,8 @@ from ._workload_monitor_api import WorkloadMonitorAPI __all__ = ['WorkloadMonitorAPI'] + +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk +patch_sdk() diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_configuration.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_configuration.py index 4d851f391621..000ee4dfd3a4 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_configuration.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_configuration.py @@ -10,7 +10,7 @@ from azure.core.configuration import Configuration from azure.core.pipeline import policies -from azure.mgmt.core.policies import ARMHttpLoggingPolicy +from azure.mgmt.core.policies import ARMHttpLoggingPolicy, AsyncARMChallengeAuthenticationPolicy from .._version import VERSION @@ -34,9 +34,9 @@ def __init__( credential: "AsyncTokenCredential", **kwargs: Any ) -> None: + super(WorkloadMonitorAPIConfiguration, self).__init__(**kwargs) if credential is None: raise ValueError("Parameter 'credential' must not be None.") - super(WorkloadMonitorAPIConfiguration, self).__init__(**kwargs) self.credential = credential self.api_version = "2020-01-13-preview" @@ -58,4 +58,4 @@ def _configure( self.redirect_policy = kwargs.get('redirect_policy') or policies.AsyncRedirectPolicy(**kwargs) self.authentication_policy = kwargs.get('authentication_policy') if self.credential and not self.authentication_policy: - self.authentication_policy = policies.AsyncBearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs) + self.authentication_policy = AsyncARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs) diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_patch.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_patch.py new file mode 100644 index 000000000000..74e48ecd07cf --- /dev/null +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass \ No newline at end of file diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_workload_monitor_api.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_workload_monitor_api.py index 73aa40a05387..45b5ffceb782 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_workload_monitor_api.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/_workload_monitor_api.py @@ -6,22 +6,22 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Optional, TYPE_CHECKING +from copy import deepcopy +from typing import Any, Awaitable, Optional, TYPE_CHECKING +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.mgmt.core import AsyncARMPipelineClient from msrest import Deserializer, Serializer +from .. import models +from ._configuration import WorkloadMonitorAPIConfiguration +from .operations import HealthMonitorsOperations, Operations + if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials_async import AsyncTokenCredential -from ._configuration import WorkloadMonitorAPIConfiguration -from .operations import Operations -from .operations import HealthMonitorsOperations -from .. import models - - -class WorkloadMonitorAPI(object): +class WorkloadMonitorAPI: """Workload Monitor API. :ivar operations: Operations operations @@ -30,28 +30,52 @@ class WorkloadMonitorAPI(object): :vartype health_monitors: workload_monitor_api.aio.operations.HealthMonitorsOperations :param credential: Credential needed for the client to connect to Azure. :type credential: ~azure.core.credentials_async.AsyncTokenCredential - :param str base_url: Service URL + :param base_url: Service URL. Default value is 'https://management.azure.com'. + :type base_url: str """ def __init__( self, credential: "AsyncTokenCredential", - base_url: Optional[str] = None, + base_url: str = "https://management.azure.com", **kwargs: Any ) -> None: - if not base_url: - base_url = 'https://management.azure.com' - self._config = WorkloadMonitorAPIConfiguration(credential, **kwargs) + self._config = WorkloadMonitorAPIConfiguration(credential=credential, **kwargs) self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs) client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) + self.health_monitors = HealthMonitorsOperations(self._client, self._config, self._serialize, self._deserialize) + + + def _send_request( + self, + request: HttpRequest, + **kwargs: Any + ) -> Awaitable[AsyncHttpResponse]: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = await client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.AsyncHttpResponse + """ - self.operations = Operations( - self._client, self._config, self._serialize, self._deserialize) - self.health_monitors = HealthMonitorsOperations( - self._client, self._config, self._serialize, self._deserialize) + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) async def close(self) -> None: await self._client.close() diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_health_monitors_operations.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_health_monitors_operations.py index 948f93cc6668..3c6972e8760c 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_health_monitors_operations.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_health_monitors_operations.py @@ -6,17 +6,22 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import datetime +import functools from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar import warnings from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async from azure.mgmt.core.exceptions import ARMErrorFormat -from ... import models - +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._health_monitors_operations import build_get_request, build_get_state_change_request, build_list_request, build_list_state_changes_request T = TypeVar('T') ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -34,7 +39,7 @@ class HealthMonitorsOperations: :param deserializer: An object model deserializer. """ - models = models + models = _models def __init__(self, client, config, serializer, deserializer) -> None: self._client = client @@ -42,6 +47,7 @@ def __init__(self, client, config, serializer, deserializer) -> None: self._deserialize = deserializer self._config = config + @distributed_trace def list( self, subscription_id: str, @@ -51,9 +57,11 @@ def list( resource_name: str, filter: Optional[str] = None, expand: Optional[str] = None, - **kwargs - ) -> AsyncIterable["models.HealthMonitorList"]: - """Get the current health status of all monitors of a virtual machine. Optional parameters: $expand (retrieve the monitor's evidence and configuration) and $filter (filter by monitor name). + **kwargs: Any + ) -> AsyncIterable["_models.HealthMonitorList"]: + """Get the current health status of all monitors of a virtual machine. Optional parameters: + $expand (retrieve the monitor's evidence and configuration) and $filter (filter by monitor + name). Get the current health status of all monitors of a virtual machine. Optional parameters: $expand (retrieve the monitor's evidence and configuration) and $filter (filter by monitor @@ -70,8 +78,8 @@ def list( :type resource_collection_name: str :param resource_name: The name of the virtual machine. :type resource_name: str - :param filter: Optionally filter by monitor name. Example: $filter=monitorName eq 'logical- - disks|C:|disk-free-space-mb.'. + :param filter: Optionally filter by monitor name. Example: $filter=monitorName eq + 'logical-disks|C:|disk-free-space-mb.'. :type filter: str :param expand: Optionally expand the monitor’s evidence and/or configuration. Example: $expand=evidence,configuration. @@ -81,47 +89,46 @@ def list( :rtype: ~azure.core.async_paging.AsyncItemPaged[~workload_monitor_api.models.HealthMonitorList] :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.HealthMonitorList"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.HealthMonitorList"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - if not next_link: - # Construct URL - url = self.list.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'providerName': self._serialize.url("provider_name", provider_name, 'str'), - 'resourceCollectionName': self._serialize.url("resource_collection_name", resource_collection_name, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + filter=filter, + expand=expand, + template_url=self.list.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + filter=filter, + expand=expand, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" return request async def extract_data(pipeline_response): - deserialized = self._deserialize('HealthMonitorList', pipeline_response) + deserialized = self._deserialize("HealthMonitorList", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) @@ -134,17 +141,19 @@ async def get_next(next_link=None): response = pipeline_response.http_response if response.status_code not in [200]: - error = self._deserialize(models.ErrorResponse, response) map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) return pipeline_response + return AsyncItemPaged( get_next, extract_data ) list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors'} # type: ignore + @distributed_trace_async async def get( self, subscription_id: str, @@ -154,9 +163,10 @@ async def get( resource_name: str, monitor_id: str, expand: Optional[str] = None, - **kwargs - ) -> "models.HealthMonitor": - """Get the current health status of a monitor of a virtual machine. Optional parameter: $expand (retrieve the monitor's evidence and configuration). + **kwargs: Any + ) -> "_models.HealthMonitor": + """Get the current health status of a monitor of a virtual machine. Optional parameter: $expand + (retrieve the monitor's evidence and configuration). Get the current health status of a monitor of a virtual machine. Optional parameter: $expand (retrieve the monitor's evidence and configuration). @@ -182,43 +192,32 @@ async def get( :rtype: ~workload_monitor_api.models.HealthMonitor :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.HealthMonitor"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.HealthMonitor"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - # Construct URL - url = self.get.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'providerName': self._serialize.url("provider_name", provider_name, 'str'), - 'resourceCollectionName': self._serialize.url("resource_collection_name", resource_collection_name, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = build_get_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + monitor_id=monitor_id, + expand=expand, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - request = self._client.get(url, query_parameters, header_parameters) pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(models.ErrorResponse, response) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) deserialized = self._deserialize('HealthMonitor', pipeline_response) @@ -227,8 +226,11 @@ async def get( return cls(pipeline_response, deserialized, {}) return deserialized + get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}'} # type: ignore + + @distributed_trace def list_state_changes( self, subscription_id: str, @@ -241,9 +243,11 @@ def list_state_changes( expand: Optional[str] = None, start_timestamp_utc: Optional[datetime.datetime] = None, end_timestamp_utc: Optional[datetime.datetime] = None, - **kwargs - ) -> AsyncIterable["models.HealthMonitorStateChangeList"]: - """Get the health state changes of a monitor of a virtual machine within the provided time window (default is the last 24 hours). Optional parameters: $expand (retrieve the monitor's evidence and configuration) and $filter (filter by heartbeat condition). + **kwargs: Any + ) -> AsyncIterable["_models.HealthMonitorStateChangeList"]: + """Get the health state changes of a monitor of a virtual machine within the provided time window + (default is the last 24 hours). Optional parameters: $expand (retrieve the monitor's evidence + and configuration) and $filter (filter by heartbeat condition). Get the health state changes of a monitor of a virtual machine within the provided time window (default is the last 24 hours). Optional parameters: $expand (retrieve the monitor's evidence @@ -272,56 +276,58 @@ def list_state_changes( :param end_timestamp_utc: The end of the time window. :type end_timestamp_utc: ~datetime.datetime :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either HealthMonitorStateChangeList or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~workload_monitor_api.models.HealthMonitorStateChangeList] + :return: An iterator like instance of either HealthMonitorStateChangeList or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~workload_monitor_api.models.HealthMonitorStateChangeList] :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.HealthMonitorStateChangeList"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.HealthMonitorStateChangeList"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - if not next_link: - # Construct URL - url = self.list_state_changes.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'providerName': self._serialize.url("provider_name", provider_name, 'str'), - 'resourceCollectionName': self._serialize.url("resource_collection_name", resource_collection_name, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - if start_timestamp_utc is not None: - query_parameters['startTimestampUtc'] = self._serialize.query("start_timestamp_utc", start_timestamp_utc, 'iso-8601') - if end_timestamp_utc is not None: - query_parameters['endTimestampUtc'] = self._serialize.query("end_timestamp_utc", end_timestamp_utc, 'iso-8601') - - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_state_changes_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + monitor_id=monitor_id, + filter=filter, + expand=expand, + start_timestamp_utc=start_timestamp_utc, + end_timestamp_utc=end_timestamp_utc, + template_url=self.list_state_changes.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_state_changes_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + monitor_id=monitor_id, + filter=filter, + expand=expand, + start_timestamp_utc=start_timestamp_utc, + end_timestamp_utc=end_timestamp_utc, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" return request async def extract_data(pipeline_response): - deserialized = self._deserialize('HealthMonitorStateChangeList', pipeline_response) + deserialized = self._deserialize("HealthMonitorStateChangeList", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) @@ -334,17 +340,19 @@ async def get_next(next_link=None): response = pipeline_response.http_response if response.status_code not in [200]: - error = self._deserialize(models.ErrorResponse, response) map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) return pipeline_response + return AsyncItemPaged( get_next, extract_data ) list_state_changes.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history'} # type: ignore + @distributed_trace_async async def get_state_change( self, subscription_id: str, @@ -355,9 +363,10 @@ async def get_state_change( monitor_id: str, timestamp_unix: str, expand: Optional[str] = None, - **kwargs - ) -> "models.HealthMonitorStateChange": - """Get the health state change of a monitor of a virtual machine at the provided timestamp. Optional parameter: $expand (retrieve the monitor's evidence and configuration). + **kwargs: Any + ) -> "_models.HealthMonitorStateChange": + """Get the health state change of a monitor of a virtual machine at the provided timestamp. + Optional parameter: $expand (retrieve the monitor's evidence and configuration). Get the health state change of a monitor of a virtual machine at the provided timestamp. Optional parameter: $expand (retrieve the monitor's evidence and configuration). @@ -385,44 +394,33 @@ async def get_state_change( :rtype: ~workload_monitor_api.models.HealthMonitorStateChange :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.HealthMonitorStateChange"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.HealthMonitorStateChange"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - # Construct URL - url = self.get_state_change.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'providerName': self._serialize.url("provider_name", provider_name, 'str'), - 'resourceCollectionName': self._serialize.url("resource_collection_name", resource_collection_name, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - 'timestampUnix': self._serialize.url("timestamp_unix", timestamp_unix, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = build_get_state_change_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + monitor_id=monitor_id, + timestamp_unix=timestamp_unix, + expand=expand, + template_url=self.get_state_change.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - request = self._client.get(url, query_parameters, header_parameters) pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(models.ErrorResponse, response) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) deserialized = self._deserialize('HealthMonitorStateChange', pipeline_response) @@ -431,4 +429,6 @@ async def get_state_change( return cls(pipeline_response, deserialized, {}) return deserialized + get_state_change.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history/{timestampUnix}'} # type: ignore + diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_monitors_operations.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_monitors_operations.py deleted file mode 100644 index 1fc775b01f2d..000000000000 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_monitors_operations.py +++ /dev/null @@ -1,421 +0,0 @@ -# coding=utf-8 -# -------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# Code generated by Microsoft (R) AutoRest Code Generator. -# Changes may cause incorrect behavior and will be lost if the code is regenerated. -# -------------------------------------------------------------------------- -import datetime -from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar -import warnings - -from azure.core.async_paging import AsyncItemPaged, AsyncList -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error -from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest -from azure.mgmt.core.exceptions import ARMErrorFormat - -from ... import models - -T = TypeVar('T') -ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] - -class MonitorsOperations: - """MonitorsOperations async operations. - - You should not instantiate this class directly. Instead, you should create a Client instance that - instantiates it for you and attaches it as an attribute. - - :ivar models: Alias to model classes used in this operation group. - :type models: ~workload_monitor_api.models - :param client: Client for service requests. - :param config: Configuration of service client. - :param serializer: An object model serializer. - :param deserializer: An object model deserializer. - """ - - models = models - - def __init__(self, client, config, serializer, deserializer) -> None: - self._client = client - self._serialize = serializer - self._deserialize = deserializer - self._config = config - - def list( - self, - subscription_id: str, - resource_group_name: str, - resource_namespace: str, - resource_type: str, - resource_name: str, - filter: Optional[str] = None, - expand: Optional[str] = None, - **kwargs - ) -> AsyncIterable["models.MonitorList"]: - """Get list of a monitors of a resource (with optional filter). - - Get list of a monitors of a resource (with optional filter). - - :param subscription_id: The subscriptionId of the resource. - :type subscription_id: str - :param resource_group_name: The resourceGroupName of the resource. - :type resource_group_name: str - :param resource_namespace: The resourceNamespace of the resource. - :type resource_namespace: str - :param resource_type: The resourceType of the resource. - :type resource_type: str - :param resource_name: The resourceType of the resource. - :type resource_name: str - :param filter: list example: $filter=monitorName eq 'logical-disks|C:|disk-free-space-mb'; - history example: $filter=isHeartbeat eq false. - :type filter: str - :param expand: ex: $expand=evidence,configuration. - :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MonitorList or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~workload_monitor_api.models.MonitorList] - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MonitorList"] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - if not next_link: - # Construct URL - url = self.list.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'resourceNamespace': self._serialize.url("resource_namespace", resource_namespace, 'str'), - 'resourceType': self._serialize.url("resource_type", resource_type, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - request = self._client.get(url, query_parameters, header_parameters) - else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize('MonitorList', pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - error = self._deserialize(models.DefaultError, response) - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged( - get_next, extract_data - ) - list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors'} # type: ignore - - async def get( - self, - subscription_id: str, - resource_group_name: str, - resource_namespace: str, - resource_type: str, - resource_name: str, - monitor_id: str, - expand: Optional[str] = None, - **kwargs - ) -> "models.Monitor": - """Get the current status of a monitor of a resource. - - Get the current status of a monitor of a resource. - - :param subscription_id: The subscriptionId of the resource. - :type subscription_id: str - :param resource_group_name: The resourceGroupName of the resource. - :type resource_group_name: str - :param resource_namespace: The resourceNamespace of the resource. - :type resource_namespace: str - :param resource_type: The resourceType of the resource. - :type resource_type: str - :param resource_name: The resourceType of the resource. - :type resource_name: str - :param monitor_id: The monitorId of the resource (url encoded). - :type monitor_id: str - :param expand: ex: $expand=evidence,configuration. - :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Monitor, or the result of cls(response) - :rtype: ~workload_monitor_api.models.Monitor - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType["models.Monitor"] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - # Construct URL - url = self.get.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'resourceNamespace': self._serialize.url("resource_namespace", resource_namespace, 'str'), - 'resourceType': self._serialize.url("resource_type", resource_type, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - request = self._client.get(url, query_parameters, header_parameters) - pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(models.DefaultError, response) - raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - - deserialized = self._deserialize('Monitor', pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}'} # type: ignore - - def list_state_changes( - self, - subscription_id: str, - resource_group_name: str, - resource_namespace: str, - resource_type: str, - resource_name: str, - monitor_id: str, - filter: Optional[str] = None, - expand: Optional[str] = None, - start_timestamp_utc: Optional[datetime.datetime] = None, - end_timestamp_utc: Optional[datetime.datetime] = None, - **kwargs - ) -> AsyncIterable["models.MonitorStateChangeList"]: - """Get history of a monitor of a resource (with optional filter). - - Get history of a monitor of a resource (with optional filter). - - :param subscription_id: The subscriptionId of the resource. - :type subscription_id: str - :param resource_group_name: The resourceGroupName of the resource. - :type resource_group_name: str - :param resource_namespace: The resourceNamespace of the resource. - :type resource_namespace: str - :param resource_type: The resourceType of the resource. - :type resource_type: str - :param resource_name: The resourceType of the resource. - :type resource_name: str - :param monitor_id: The monitorId of the resource (url encoded). - :type monitor_id: str - :param filter: list example: $filter=monitorName eq 'logical-disks|C:|disk-free-space-mb'; - history example: $filter=isHeartbeat eq false. - :type filter: str - :param expand: ex: $expand=evidence,configuration. - :type expand: str - :param start_timestamp_utc: The start Timestamp for the desired history. - :type start_timestamp_utc: ~datetime.datetime - :param end_timestamp_utc: The end Timestamp for the desired history. - :type end_timestamp_utc: ~datetime.datetime - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MonitorStateChangeList or the result of cls(response) - :rtype: ~azure.core.async_paging.AsyncItemPaged[~workload_monitor_api.models.MonitorStateChangeList] - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MonitorStateChangeList"] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - if not next_link: - # Construct URL - url = self.list_state_changes.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'resourceNamespace': self._serialize.url("resource_namespace", resource_namespace, 'str'), - 'resourceType': self._serialize.url("resource_type", resource_type, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - if start_timestamp_utc is not None: - query_parameters['startTimestampUtc'] = self._serialize.query("start_timestamp_utc", start_timestamp_utc, 'iso-8601') - if end_timestamp_utc is not None: - query_parameters['endTimestampUtc'] = self._serialize.query("end_timestamp_utc", end_timestamp_utc, 'iso-8601') - - request = self._client.get(url, query_parameters, header_parameters) - else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) - return request - - async def extract_data(pipeline_response): - deserialized = self._deserialize('MonitorStateChangeList', pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) - return deserialized.next_link or None, AsyncList(list_of_elem) - - async def get_next(next_link=None): - request = prepare_request(next_link) - - pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - error = self._deserialize(models.DefaultError, response) - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - - return pipeline_response - - return AsyncItemPaged( - get_next, extract_data - ) - list_state_changes.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history'} # type: ignore - - async def get_state_change( - self, - subscription_id: str, - resource_group_name: str, - resource_namespace: str, - resource_type: str, - resource_name: str, - monitor_id: str, - timestamp_unix: str, - expand: Optional[str] = None, - **kwargs - ) -> "models.MonitorStateChange": - """Get the status of a monitor at a specific timestamp in history. - - Get the status of a monitor at a specific timestamp in history. - - :param subscription_id: The subscriptionId of the resource. - :type subscription_id: str - :param resource_group_name: The resourceGroupName of the resource. - :type resource_group_name: str - :param resource_namespace: The resourceNamespace of the resource. - :type resource_namespace: str - :param resource_type: The resourceType of the resource. - :type resource_type: str - :param resource_name: The resourceType of the resource. - :type resource_name: str - :param monitor_id: The monitorId of the resource (url encoded). - :type monitor_id: str - :param timestamp_unix: The timestamp of the state change (Unix format). - :type timestamp_unix: str - :param expand: ex: $expand=evidence,configuration. - :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: MonitorStateChange, or the result of cls(response) - :rtype: ~workload_monitor_api.models.MonitorStateChange - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MonitorStateChange"] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - # Construct URL - url = self.get_state_change.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'resourceNamespace': self._serialize.url("resource_namespace", resource_namespace, 'str'), - 'resourceType': self._serialize.url("resource_type", resource_type, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - 'timestampUnix': self._serialize.url("timestamp_unix", timestamp_unix, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - request = self._client.get(url, query_parameters, header_parameters) - pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(models.DefaultError, response) - raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - - deserialized = self._deserialize('MonitorStateChange', pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - get_state_change.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history/{timestampUnix}'} # type: ignore diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_operations.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_operations.py index e796711712b7..912b70b8ac96 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_operations.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/aio/operations/_operations.py @@ -5,17 +5,22 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +import functools from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar import warnings from azure.core.async_paging import AsyncItemPaged, AsyncList from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async from azure.mgmt.core.exceptions import ARMErrorFormat -from ... import models - +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._operations import build_list_request T = TypeVar('T') ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -33,7 +38,7 @@ class Operations: :param deserializer: An object model deserializer. """ - models = models + models = _models def __init__(self, client, config, serializer, deserializer) -> None: self._client = client @@ -41,10 +46,11 @@ def __init__(self, client, config, serializer, deserializer) -> None: self._deserialize = deserializer self._config = config + @distributed_trace def list( self, - **kwargs - ) -> AsyncIterable["models.OperationList"]: + **kwargs: Any + ) -> AsyncIterable["_models.OperationList"]: """Get a list of all available REST API operations. Get a list of all available REST API operations. @@ -54,35 +60,32 @@ def list( :rtype: ~azure.core.async_paging.AsyncItemPaged[~workload_monitor_api.models.OperationList] :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.OperationList"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.OperationList"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - if not next_link: - # Construct URL - url = self.list.metadata['url'] # type: ignore - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = build_list_request( + template_url=self.list.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - request = self._client.get(url, query_parameters, header_parameters) else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_request( + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" return request async def extract_data(pipeline_response): - deserialized = self._deserialize('OperationList', pipeline_response) + deserialized = self._deserialize("OperationList", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) @@ -95,12 +98,13 @@ async def get_next(next_link=None): response = pipeline_response.http_response if response.status_code not in [200]: - error = self._deserialize(models.ErrorResponse, response) map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) return pipeline_response + return AsyncItemPaged( get_next, extract_data ) diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/__init__.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/__init__.py index 33767b58242b..042b5ed22fe2 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/__init__.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/__init__.py @@ -6,30 +6,18 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -try: - from ._models_py3 import ErrorDetails - from ._models_py3 import ErrorResponse - from ._models_py3 import ErrorResponseError - from ._models_py3 import HealthMonitor - from ._models_py3 import HealthMonitorList - from ._models_py3 import HealthMonitorStateChange - from ._models_py3 import HealthMonitorStateChangeList - from ._models_py3 import Operation - from ._models_py3 import OperationDisplay - from ._models_py3 import OperationList - from ._models_py3 import Resource -except (SyntaxError, ImportError): - from ._models import ErrorDetails # type: ignore - from ._models import ErrorResponse # type: ignore - from ._models import ErrorResponseError # type: ignore - from ._models import HealthMonitor # type: ignore - from ._models import HealthMonitorList # type: ignore - from ._models import HealthMonitorStateChange # type: ignore - from ._models import HealthMonitorStateChangeList # type: ignore - from ._models import Operation # type: ignore - from ._models import OperationDisplay # type: ignore - from ._models import OperationList # type: ignore - from ._models import Resource # type: ignore +from ._models_py3 import ErrorDetails +from ._models_py3 import ErrorResponse +from ._models_py3 import ErrorResponseError +from ._models_py3 import HealthMonitor +from ._models_py3 import HealthMonitorList +from ._models_py3 import HealthMonitorStateChange +from ._models_py3 import HealthMonitorStateChangeList +from ._models_py3 import Operation +from ._models_py3 import OperationDisplay +from ._models_py3 import OperationList +from ._models_py3 import Resource + from ._workload_monitor_api_enums import ( HealthState, diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_models.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_models.py deleted file mode 100644 index b4cc1b92f4f9..000000000000 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_models.py +++ /dev/null @@ -1,416 +0,0 @@ -# coding=utf-8 -# -------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# Code generated by Microsoft (R) AutoRest Code Generator. -# Changes may cause incorrect behavior and will be lost if the code is regenerated. -# -------------------------------------------------------------------------- - -from azure.core.exceptions import HttpResponseError -import msrest.serialization - - -class ErrorDetails(msrest.serialization.Model): - """Error details. - - :param code: Error code identifying the specific error. - :type code: str - :param message: A human-readable error message. - :type message: str - """ - - _attribute_map = { - 'code': {'key': 'code', 'type': 'str'}, - 'message': {'key': 'message', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(ErrorDetails, self).__init__(**kwargs) - self.code = kwargs.get('code', None) - self.message = kwargs.get('message', None) - - -class ErrorResponse(msrest.serialization.Model): - """Error response. - - :param error: Error info. - :type error: ~workload_monitor_api.models.ErrorResponseError - """ - - _attribute_map = { - 'error': {'key': 'error', 'type': 'ErrorResponseError'}, - } - - def __init__( - self, - **kwargs - ): - super(ErrorResponse, self).__init__(**kwargs) - self.error = kwargs.get('error', None) - - -class ErrorResponseError(msrest.serialization.Model): - """Error info. - - :param code: Service-defined error code. This code serves as a sub-status for the HTTP error - code specified in the response. - :type code: str - :param message: Human-readable representation of the error. - :type message: str - :param details: Error details. - :type details: list[~workload_monitor_api.models.ErrorDetails] - """ - - _attribute_map = { - 'code': {'key': 'code', 'type': 'str'}, - 'message': {'key': 'message', 'type': 'str'}, - 'details': {'key': 'details', 'type': '[ErrorDetails]'}, - } - - def __init__( - self, - **kwargs - ): - super(ErrorResponseError, self).__init__(**kwargs) - self.code = kwargs.get('code', None) - self.message = kwargs.get('message', None) - self.details = kwargs.get('details', None) - - -class Resource(msrest.serialization.Model): - """The resource model definition for the ARM proxy resource, 'microsoft.workloadmonitor/monitors'. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar id: The resource Id. - :vartype id: str - :ivar name: The resource name. - :vartype name: str - :ivar type: The resource type. - :vartype type: str - """ - - _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(Resource, self).__init__(**kwargs) - self.id = None - self.name = None - self.type = None - - -class HealthMonitor(Resource): - """Information about the monitor’s current health status. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar id: The resource Id. - :vartype id: str - :ivar name: The resource name. - :vartype name: str - :ivar type: The resource type. - :vartype type: str - :param monitor_name: Human-readable name of the monitor. - :type monitor_name: str - :param monitor_type: Type of the monitor. - :type monitor_type: str - :param monitored_object: Dynamic monitored object of the monitor. - :type monitored_object: str - :param parent_monitor_name: Name of the parent monitor. - :type parent_monitor_name: str - :ivar previous_monitor_state: Previous health state of the monitor. Possible values include: - "Healthy", "Critical", "Warning", "Unknown", "Disabled", "None". - :vartype previous_monitor_state: str or ~workload_monitor_api.models.HealthState - :ivar current_monitor_state: Current health state of the monitor. Possible values include: - "Healthy", "Critical", "Warning", "Unknown", "Disabled", "None". - :vartype current_monitor_state: str or ~workload_monitor_api.models.HealthState - :param evaluation_timestamp: Timestamp of the monitor's last health evaluation. - :type evaluation_timestamp: str - :param current_state_first_observed_timestamp: Timestamp of the monitor's last health state - change. - :type current_state_first_observed_timestamp: str - :param last_reported_timestamp: Timestamp of the monitor's last reported health state. - :type last_reported_timestamp: str - :param evidence: Evidence validating the monitor's current health state. - :type evidence: object - :param monitor_configuration: The configuration settings at the time of the monitor's health - evaluation. - :type monitor_configuration: object - """ - - _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'previous_monitor_state': {'readonly': True}, - 'current_monitor_state': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'monitor_name': {'key': 'properties.monitorName', 'type': 'str'}, - 'monitor_type': {'key': 'properties.monitorType', 'type': 'str'}, - 'monitored_object': {'key': 'properties.monitoredObject', 'type': 'str'}, - 'parent_monitor_name': {'key': 'properties.parentMonitorName', 'type': 'str'}, - 'previous_monitor_state': {'key': 'properties.previousMonitorState', 'type': 'str'}, - 'current_monitor_state': {'key': 'properties.currentMonitorState', 'type': 'str'}, - 'evaluation_timestamp': {'key': 'properties.evaluationTimestamp', 'type': 'str'}, - 'current_state_first_observed_timestamp': {'key': 'properties.currentStateFirstObservedTimestamp', 'type': 'str'}, - 'last_reported_timestamp': {'key': 'properties.lastReportedTimestamp', 'type': 'str'}, - 'evidence': {'key': 'properties.evidence', 'type': 'object'}, - 'monitor_configuration': {'key': 'properties.monitorConfiguration', 'type': 'object'}, - } - - def __init__( - self, - **kwargs - ): - super(HealthMonitor, self).__init__(**kwargs) - self.monitor_name = kwargs.get('monitor_name', None) - self.monitor_type = kwargs.get('monitor_type', None) - self.monitored_object = kwargs.get('monitored_object', None) - self.parent_monitor_name = kwargs.get('parent_monitor_name', None) - self.previous_monitor_state = None - self.current_monitor_state = None - self.evaluation_timestamp = kwargs.get('evaluation_timestamp', None) - self.current_state_first_observed_timestamp = kwargs.get('current_state_first_observed_timestamp', None) - self.last_reported_timestamp = kwargs.get('last_reported_timestamp', None) - self.evidence = kwargs.get('evidence', None) - self.monitor_configuration = kwargs.get('monitor_configuration', None) - - -class HealthMonitorList(msrest.serialization.Model): - """Information about the current health statuses of the monitors. - - :param value: Array of health monitors of the virtual machine. - :type value: list[~workload_monitor_api.models.HealthMonitor] - :param next_link: Link to next page if the list is too long. - :type next_link: str - """ - - _attribute_map = { - 'value': {'key': 'value', 'type': '[HealthMonitor]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(HealthMonitorList, self).__init__(**kwargs) - self.value = kwargs.get('value', None) - self.next_link = kwargs.get('next_link', None) - - -class HealthMonitorStateChange(Resource): - """Information about the monitor’s health state change at the provided timestamp. - - Variables are only populated by the server, and will be ignored when sending a request. - - :ivar id: The resource Id. - :vartype id: str - :ivar name: The resource name. - :vartype name: str - :ivar type: The resource type. - :vartype type: str - :param monitor_name: Human-readable name of the monitor. - :type monitor_name: str - :param monitor_type: Type of the monitor. - :type monitor_type: str - :param monitored_object: Dynamic monitored object of the monitor. - :type monitored_object: str - :param evaluation_timestamp: Timestamp of the monitor's last health evaluation. - :type evaluation_timestamp: str - :param current_state_first_observed_timestamp: Timestamp of the monitor's last health state - change. - :type current_state_first_observed_timestamp: str - :ivar previous_monitor_state: Previous health state of the monitor. Possible values include: - "Healthy", "Critical", "Warning", "Unknown", "Disabled", "None". - :vartype previous_monitor_state: str or ~workload_monitor_api.models.HealthState - :ivar current_monitor_state: Current health state of the monitor. Possible values include: - "Healthy", "Critical", "Warning", "Unknown", "Disabled", "None". - :vartype current_monitor_state: str or ~workload_monitor_api.models.HealthState - :param evidence: Evidence validating the monitor's current health state. - :type evidence: object - :param monitor_configuration: The configuration settings at the time of the monitor's health - evaluation. - :type monitor_configuration: object - """ - - _validation = { - 'id': {'readonly': True}, - 'name': {'readonly': True}, - 'type': {'readonly': True}, - 'previous_monitor_state': {'readonly': True}, - 'current_monitor_state': {'readonly': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'name': {'key': 'name', 'type': 'str'}, - 'type': {'key': 'type', 'type': 'str'}, - 'monitor_name': {'key': 'properties.monitorName', 'type': 'str'}, - 'monitor_type': {'key': 'properties.monitorType', 'type': 'str'}, - 'monitored_object': {'key': 'properties.monitoredObject', 'type': 'str'}, - 'evaluation_timestamp': {'key': 'properties.evaluationTimestamp', 'type': 'str'}, - 'current_state_first_observed_timestamp': {'key': 'properties.currentStateFirstObservedTimestamp', 'type': 'str'}, - 'previous_monitor_state': {'key': 'properties.previousMonitorState', 'type': 'str'}, - 'current_monitor_state': {'key': 'properties.currentMonitorState', 'type': 'str'}, - 'evidence': {'key': 'properties.evidence', 'type': 'object'}, - 'monitor_configuration': {'key': 'properties.monitorConfiguration', 'type': 'object'}, - } - - def __init__( - self, - **kwargs - ): - super(HealthMonitorStateChange, self).__init__(**kwargs) - self.monitor_name = kwargs.get('monitor_name', None) - self.monitor_type = kwargs.get('monitor_type', None) - self.monitored_object = kwargs.get('monitored_object', None) - self.evaluation_timestamp = kwargs.get('evaluation_timestamp', None) - self.current_state_first_observed_timestamp = kwargs.get('current_state_first_observed_timestamp', None) - self.previous_monitor_state = None - self.current_monitor_state = None - self.evidence = kwargs.get('evidence', None) - self.monitor_configuration = kwargs.get('monitor_configuration', None) - - -class HealthMonitorStateChangeList(msrest.serialization.Model): - """Information about the health state changes of the monitor within the provided time window. - - :param value: Array of health state changes within the specified time window. - :type value: list[~workload_monitor_api.models.HealthMonitorStateChange] - :param next_link: Link to next page if the list is too long. - :type next_link: str - """ - - _attribute_map = { - 'value': {'key': 'value', 'type': '[HealthMonitorStateChange]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(HealthMonitorStateChangeList, self).__init__(**kwargs) - self.value = kwargs.get('value', None) - self.next_link = kwargs.get('next_link', None) - - -class Operation(msrest.serialization.Model): - """Operation supported by the resource provider. - - All required parameters must be populated in order to send to Azure. - - :param name: Required. The name of the operation being performed on this particular object. - :type name: str - :param display: Required. The localized display information for this particular operation or - action. - :type display: ~workload_monitor_api.models.OperationDisplay - :param origin: Required. The intended executor of the operation. - :type origin: str - """ - - _validation = { - 'name': {'required': True}, - 'display': {'required': True}, - 'origin': {'required': True}, - } - - _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, - 'display': {'key': 'display', 'type': 'OperationDisplay'}, - 'origin': {'key': 'origin', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(Operation, self).__init__(**kwargs) - self.name = kwargs['name'] - self.display = kwargs['display'] - self.origin = kwargs['origin'] - - -class OperationDisplay(msrest.serialization.Model): - """The localized display information for this particular operation or action. - - All required parameters must be populated in order to send to Azure. - - :param provider: Required. Operation resource provider name. - :type provider: str - :param resource: Required. Resource on which the operation is performed. - :type resource: str - :param operation: Required. Human-readable, friendly name for the operation. - :type operation: str - :param description: Required. Operation description. - :type description: str - """ - - _validation = { - 'provider': {'required': True}, - 'resource': {'required': True}, - 'operation': {'required': True}, - 'description': {'required': True}, - } - - _attribute_map = { - 'provider': {'key': 'provider', 'type': 'str'}, - 'resource': {'key': 'resource', 'type': 'str'}, - 'operation': {'key': 'operation', 'type': 'str'}, - 'description': {'key': 'description', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(OperationDisplay, self).__init__(**kwargs) - self.provider = kwargs['provider'] - self.resource = kwargs['resource'] - self.operation = kwargs['operation'] - self.description = kwargs['description'] - - -class OperationList(msrest.serialization.Model): - """List of available REST API operations. - - :param value: Array of available REST API operations. - :type value: list[~workload_monitor_api.models.Operation] - :param next_link: Link to next page if the list is too long. - :type next_link: str - """ - - _attribute_map = { - 'value': {'key': 'value', 'type': '[Operation]'}, - 'next_link': {'key': 'nextLink', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(OperationList, self).__init__(**kwargs) - self.value = kwargs.get('value', None) - self.next_link = kwargs.get('next_link', None) diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_models_py3.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_models_py3.py index 5c7eef2d7c8d..28f9fbf41a62 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_models_py3.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_models_py3.py @@ -6,7 +6,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import List, Optional +from typing import Any, List, Optional from azure.core.exceptions import HttpResponseError import msrest.serialization @@ -15,10 +15,10 @@ class ErrorDetails(msrest.serialization.Model): """Error details. - :param code: Error code identifying the specific error. - :type code: str - :param message: A human-readable error message. - :type message: str + :ivar code: Error code identifying the specific error. + :vartype code: str + :ivar message: A human-readable error message. + :vartype message: str """ _attribute_map = { @@ -33,6 +33,12 @@ def __init__( message: Optional[str] = None, **kwargs ): + """ + :keyword code: Error code identifying the specific error. + :paramtype code: str + :keyword message: A human-readable error message. + :paramtype message: str + """ super(ErrorDetails, self).__init__(**kwargs) self.code = code self.message = message @@ -41,8 +47,8 @@ def __init__( class ErrorResponse(msrest.serialization.Model): """Error response. - :param error: Error info. - :type error: ~workload_monitor_api.models.ErrorResponseError + :ivar error: Error info. + :vartype error: ~workload_monitor_api.models.ErrorResponseError """ _attribute_map = { @@ -55,6 +61,10 @@ def __init__( error: Optional["ErrorResponseError"] = None, **kwargs ): + """ + :keyword error: Error info. + :paramtype error: ~workload_monitor_api.models.ErrorResponseError + """ super(ErrorResponse, self).__init__(**kwargs) self.error = error @@ -62,13 +72,13 @@ def __init__( class ErrorResponseError(msrest.serialization.Model): """Error info. - :param code: Service-defined error code. This code serves as a sub-status for the HTTP error + :ivar code: Service-defined error code. This code serves as a sub-status for the HTTP error code specified in the response. - :type code: str - :param message: Human-readable representation of the error. - :type message: str - :param details: Error details. - :type details: list[~workload_monitor_api.models.ErrorDetails] + :vartype code: str + :ivar message: Human-readable representation of the error. + :vartype message: str + :ivar details: Error details. + :vartype details: list[~workload_monitor_api.models.ErrorDetails] """ _attribute_map = { @@ -85,6 +95,15 @@ def __init__( details: Optional[List["ErrorDetails"]] = None, **kwargs ): + """ + :keyword code: Service-defined error code. This code serves as a sub-status for the HTTP error + code specified in the response. + :paramtype code: str + :keyword message: Human-readable representation of the error. + :paramtype message: str + :keyword details: Error details. + :paramtype details: list[~workload_monitor_api.models.ErrorDetails] + """ super(ErrorResponseError, self).__init__(**kwargs) self.code = code self.message = message @@ -120,6 +139,8 @@ def __init__( self, **kwargs ): + """ + """ super(Resource, self).__init__(**kwargs) self.id = None self.name = None @@ -137,32 +158,32 @@ class HealthMonitor(Resource): :vartype name: str :ivar type: The resource type. :vartype type: str - :param monitor_name: Human-readable name of the monitor. - :type monitor_name: str - :param monitor_type: Type of the monitor. - :type monitor_type: str - :param monitored_object: Dynamic monitored object of the monitor. - :type monitored_object: str - :param parent_monitor_name: Name of the parent monitor. - :type parent_monitor_name: str + :ivar monitor_name: Human-readable name of the monitor. + :vartype monitor_name: str + :ivar monitor_type: Type of the monitor. + :vartype monitor_type: str + :ivar monitored_object: Dynamic monitored object of the monitor. + :vartype monitored_object: str + :ivar parent_monitor_name: Name of the parent monitor. + :vartype parent_monitor_name: str :ivar previous_monitor_state: Previous health state of the monitor. Possible values include: "Healthy", "Critical", "Warning", "Unknown", "Disabled", "None". :vartype previous_monitor_state: str or ~workload_monitor_api.models.HealthState :ivar current_monitor_state: Current health state of the monitor. Possible values include: "Healthy", "Critical", "Warning", "Unknown", "Disabled", "None". :vartype current_monitor_state: str or ~workload_monitor_api.models.HealthState - :param evaluation_timestamp: Timestamp of the monitor's last health evaluation. - :type evaluation_timestamp: str - :param current_state_first_observed_timestamp: Timestamp of the monitor's last health state + :ivar evaluation_timestamp: Timestamp of the monitor's last health evaluation. + :vartype evaluation_timestamp: str + :ivar current_state_first_observed_timestamp: Timestamp of the monitor's last health state change. - :type current_state_first_observed_timestamp: str - :param last_reported_timestamp: Timestamp of the monitor's last reported health state. - :type last_reported_timestamp: str - :param evidence: Evidence validating the monitor's current health state. - :type evidence: object - :param monitor_configuration: The configuration settings at the time of the monitor's health + :vartype current_state_first_observed_timestamp: str + :ivar last_reported_timestamp: Timestamp of the monitor's last reported health state. + :vartype last_reported_timestamp: str + :ivar evidence: Evidence validating the monitor's current health state. + :vartype evidence: any + :ivar monitor_configuration: The configuration settings at the time of the monitor's health evaluation. - :type monitor_configuration: object + :vartype monitor_configuration: any """ _validation = { @@ -200,10 +221,32 @@ def __init__( evaluation_timestamp: Optional[str] = None, current_state_first_observed_timestamp: Optional[str] = None, last_reported_timestamp: Optional[str] = None, - evidence: Optional[object] = None, - monitor_configuration: Optional[object] = None, + evidence: Optional[Any] = None, + monitor_configuration: Optional[Any] = None, **kwargs ): + """ + :keyword monitor_name: Human-readable name of the monitor. + :paramtype monitor_name: str + :keyword monitor_type: Type of the monitor. + :paramtype monitor_type: str + :keyword monitored_object: Dynamic monitored object of the monitor. + :paramtype monitored_object: str + :keyword parent_monitor_name: Name of the parent monitor. + :paramtype parent_monitor_name: str + :keyword evaluation_timestamp: Timestamp of the monitor's last health evaluation. + :paramtype evaluation_timestamp: str + :keyword current_state_first_observed_timestamp: Timestamp of the monitor's last health state + change. + :paramtype current_state_first_observed_timestamp: str + :keyword last_reported_timestamp: Timestamp of the monitor's last reported health state. + :paramtype last_reported_timestamp: str + :keyword evidence: Evidence validating the monitor's current health state. + :paramtype evidence: any + :keyword monitor_configuration: The configuration settings at the time of the monitor's health + evaluation. + :paramtype monitor_configuration: any + """ super(HealthMonitor, self).__init__(**kwargs) self.monitor_name = monitor_name self.monitor_type = monitor_type @@ -221,10 +264,10 @@ def __init__( class HealthMonitorList(msrest.serialization.Model): """Information about the current health statuses of the monitors. - :param value: Array of health monitors of the virtual machine. - :type value: list[~workload_monitor_api.models.HealthMonitor] - :param next_link: Link to next page if the list is too long. - :type next_link: str + :ivar value: Array of health monitors of the virtual machine. + :vartype value: list[~workload_monitor_api.models.HealthMonitor] + :ivar next_link: Link to next page if the list is too long. + :vartype next_link: str """ _attribute_map = { @@ -239,6 +282,12 @@ def __init__( next_link: Optional[str] = None, **kwargs ): + """ + :keyword value: Array of health monitors of the virtual machine. + :paramtype value: list[~workload_monitor_api.models.HealthMonitor] + :keyword next_link: Link to next page if the list is too long. + :paramtype next_link: str + """ super(HealthMonitorList, self).__init__(**kwargs) self.value = value self.next_link = next_link @@ -255,28 +304,28 @@ class HealthMonitorStateChange(Resource): :vartype name: str :ivar type: The resource type. :vartype type: str - :param monitor_name: Human-readable name of the monitor. - :type monitor_name: str - :param monitor_type: Type of the monitor. - :type monitor_type: str - :param monitored_object: Dynamic monitored object of the monitor. - :type monitored_object: str - :param evaluation_timestamp: Timestamp of the monitor's last health evaluation. - :type evaluation_timestamp: str - :param current_state_first_observed_timestamp: Timestamp of the monitor's last health state + :ivar monitor_name: Human-readable name of the monitor. + :vartype monitor_name: str + :ivar monitor_type: Type of the monitor. + :vartype monitor_type: str + :ivar monitored_object: Dynamic monitored object of the monitor. + :vartype monitored_object: str + :ivar evaluation_timestamp: Timestamp of the monitor's last health evaluation. + :vartype evaluation_timestamp: str + :ivar current_state_first_observed_timestamp: Timestamp of the monitor's last health state change. - :type current_state_first_observed_timestamp: str + :vartype current_state_first_observed_timestamp: str :ivar previous_monitor_state: Previous health state of the monitor. Possible values include: "Healthy", "Critical", "Warning", "Unknown", "Disabled", "None". :vartype previous_monitor_state: str or ~workload_monitor_api.models.HealthState :ivar current_monitor_state: Current health state of the monitor. Possible values include: "Healthy", "Critical", "Warning", "Unknown", "Disabled", "None". :vartype current_monitor_state: str or ~workload_monitor_api.models.HealthState - :param evidence: Evidence validating the monitor's current health state. - :type evidence: object - :param monitor_configuration: The configuration settings at the time of the monitor's health + :ivar evidence: Evidence validating the monitor's current health state. + :vartype evidence: any + :ivar monitor_configuration: The configuration settings at the time of the monitor's health evaluation. - :type monitor_configuration: object + :vartype monitor_configuration: any """ _validation = { @@ -310,10 +359,28 @@ def __init__( monitored_object: Optional[str] = None, evaluation_timestamp: Optional[str] = None, current_state_first_observed_timestamp: Optional[str] = None, - evidence: Optional[object] = None, - monitor_configuration: Optional[object] = None, + evidence: Optional[Any] = None, + monitor_configuration: Optional[Any] = None, **kwargs ): + """ + :keyword monitor_name: Human-readable name of the monitor. + :paramtype monitor_name: str + :keyword monitor_type: Type of the monitor. + :paramtype monitor_type: str + :keyword monitored_object: Dynamic monitored object of the monitor. + :paramtype monitored_object: str + :keyword evaluation_timestamp: Timestamp of the monitor's last health evaluation. + :paramtype evaluation_timestamp: str + :keyword current_state_first_observed_timestamp: Timestamp of the monitor's last health state + change. + :paramtype current_state_first_observed_timestamp: str + :keyword evidence: Evidence validating the monitor's current health state. + :paramtype evidence: any + :keyword monitor_configuration: The configuration settings at the time of the monitor's health + evaluation. + :paramtype monitor_configuration: any + """ super(HealthMonitorStateChange, self).__init__(**kwargs) self.monitor_name = monitor_name self.monitor_type = monitor_type @@ -329,10 +396,10 @@ def __init__( class HealthMonitorStateChangeList(msrest.serialization.Model): """Information about the health state changes of the monitor within the provided time window. - :param value: Array of health state changes within the specified time window. - :type value: list[~workload_monitor_api.models.HealthMonitorStateChange] - :param next_link: Link to next page if the list is too long. - :type next_link: str + :ivar value: Array of health state changes within the specified time window. + :vartype value: list[~workload_monitor_api.models.HealthMonitorStateChange] + :ivar next_link: Link to next page if the list is too long. + :vartype next_link: str """ _attribute_map = { @@ -347,6 +414,12 @@ def __init__( next_link: Optional[str] = None, **kwargs ): + """ + :keyword value: Array of health state changes within the specified time window. + :paramtype value: list[~workload_monitor_api.models.HealthMonitorStateChange] + :keyword next_link: Link to next page if the list is too long. + :paramtype next_link: str + """ super(HealthMonitorStateChangeList, self).__init__(**kwargs) self.value = value self.next_link = next_link @@ -357,13 +430,13 @@ class Operation(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :param name: Required. The name of the operation being performed on this particular object. - :type name: str - :param display: Required. The localized display information for this particular operation or + :ivar name: Required. The name of the operation being performed on this particular object. + :vartype name: str + :ivar display: Required. The localized display information for this particular operation or action. - :type display: ~workload_monitor_api.models.OperationDisplay - :param origin: Required. The intended executor of the operation. - :type origin: str + :vartype display: ~workload_monitor_api.models.OperationDisplay + :ivar origin: Required. The intended executor of the operation. + :vartype origin: str """ _validation = { @@ -386,6 +459,15 @@ def __init__( origin: str, **kwargs ): + """ + :keyword name: Required. The name of the operation being performed on this particular object. + :paramtype name: str + :keyword display: Required. The localized display information for this particular operation or + action. + :paramtype display: ~workload_monitor_api.models.OperationDisplay + :keyword origin: Required. The intended executor of the operation. + :paramtype origin: str + """ super(Operation, self).__init__(**kwargs) self.name = name self.display = display @@ -397,14 +479,14 @@ class OperationDisplay(msrest.serialization.Model): All required parameters must be populated in order to send to Azure. - :param provider: Required. Operation resource provider name. - :type provider: str - :param resource: Required. Resource on which the operation is performed. - :type resource: str - :param operation: Required. Human-readable, friendly name for the operation. - :type operation: str - :param description: Required. Operation description. - :type description: str + :ivar provider: Required. Operation resource provider name. + :vartype provider: str + :ivar resource: Required. Resource on which the operation is performed. + :vartype resource: str + :ivar operation: Required. Human-readable, friendly name for the operation. + :vartype operation: str + :ivar description: Required. Operation description. + :vartype description: str """ _validation = { @@ -430,6 +512,16 @@ def __init__( description: str, **kwargs ): + """ + :keyword provider: Required. Operation resource provider name. + :paramtype provider: str + :keyword resource: Required. Resource on which the operation is performed. + :paramtype resource: str + :keyword operation: Required. Human-readable, friendly name for the operation. + :paramtype operation: str + :keyword description: Required. Operation description. + :paramtype description: str + """ super(OperationDisplay, self).__init__(**kwargs) self.provider = provider self.resource = resource @@ -440,10 +532,10 @@ def __init__( class OperationList(msrest.serialization.Model): """List of available REST API operations. - :param value: Array of available REST API operations. - :type value: list[~workload_monitor_api.models.Operation] - :param next_link: Link to next page if the list is too long. - :type next_link: str + :ivar value: Array of available REST API operations. + :vartype value: list[~workload_monitor_api.models.Operation] + :ivar next_link: Link to next page if the list is too long. + :vartype next_link: str """ _attribute_map = { @@ -458,6 +550,12 @@ def __init__( next_link: Optional[str] = None, **kwargs ): + """ + :keyword value: Array of available REST API operations. + :paramtype value: list[~workload_monitor_api.models.Operation] + :keyword next_link: Link to next page if the list is too long. + :paramtype next_link: str + """ super(OperationList, self).__init__(**kwargs) self.value = value self.next_link = next_link diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_workload_monitor_api_enums.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_workload_monitor_api_enums.py index 83b4a198fda8..4433f83651d5 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_workload_monitor_api_enums.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/models/_workload_monitor_api_enums.py @@ -6,27 +6,12 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from enum import Enum, EnumMeta +from enum import Enum from six import with_metaclass +from azure.core import CaseInsensitiveEnumMeta -class _CaseInsensitiveEnumMeta(EnumMeta): - def __getitem__(self, name): - return super().__getitem__(name.upper()) - def __getattr__(cls, name): - """Return the enum member matching `name` - We use __getattr__ instead of descriptors or inserting into the enum - class' __dict__ in order to support `name` and `value` being both - properties for enum members (which live in the class' __dict__) and - enum members themselves. - """ - try: - return cls._member_map_[name.upper()] - except KeyError: - raise AttributeError(name) - - -class HealthState(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): +class HealthState(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): """One of health states - healthy, critical, warning, unknown, none, disabled. """ diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_health_monitors_operations.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_health_monitors_operations.py index 4e6a6bccf3d6..b7019ddfc5af 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_health_monitors_operations.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_health_monitors_operations.py @@ -6,23 +6,217 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import datetime -from typing import TYPE_CHECKING +import functools +from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar import warnings from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpRequest, HttpResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace from azure.mgmt.core.exceptions import ARMErrorFormat - -from .. import models - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar - - T = TypeVar('T') - ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] +from msrest import Serializer + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + +def build_list_request( + subscription_id: str, + resource_group_name: str, + provider_name: str, + resource_collection_name: str, + resource_name: str, + *, + filter: Optional[str] = None, + expand: Optional[str] = None, + **kwargs: Any +) -> HttpRequest: + api_version = "2020-01-13-preview" + accept = "application/json" + # Construct URL + url = kwargs.pop("template_url", '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors') + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), + "providerName": _SERIALIZER.url("provider_name", provider_name, 'str'), + "resourceCollectionName": _SERIALIZER.url("resource_collection_name", resource_collection_name, 'str'), + "resourceName": _SERIALIZER.url("resource_name", resource_name, 'str'), + } + + url = _format_url_section(url, **path_format_arguments) + + # Construct parameters + query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + if filter is not None: + query_parameters['$filter'] = _SERIALIZER.query("filter", filter, 'str') + if expand is not None: + query_parameters['$expand'] = _SERIALIZER.query("expand", expand, 'str') + + # Construct headers + header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=url, + params=query_parameters, + headers=header_parameters, + **kwargs + ) + + +def build_get_request( + subscription_id: str, + resource_group_name: str, + provider_name: str, + resource_collection_name: str, + resource_name: str, + monitor_id: str, + *, + expand: Optional[str] = None, + **kwargs: Any +) -> HttpRequest: + api_version = "2020-01-13-preview" + accept = "application/json" + # Construct URL + url = kwargs.pop("template_url", '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}') + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), + "providerName": _SERIALIZER.url("provider_name", provider_name, 'str'), + "resourceCollectionName": _SERIALIZER.url("resource_collection_name", resource_collection_name, 'str'), + "resourceName": _SERIALIZER.url("resource_name", resource_name, 'str'), + "monitorId": _SERIALIZER.url("monitor_id", monitor_id, 'str'), + } + + url = _format_url_section(url, **path_format_arguments) + + # Construct parameters + query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + if expand is not None: + query_parameters['$expand'] = _SERIALIZER.query("expand", expand, 'str') + + # Construct headers + header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=url, + params=query_parameters, + headers=header_parameters, + **kwargs + ) + + +def build_list_state_changes_request( + subscription_id: str, + resource_group_name: str, + provider_name: str, + resource_collection_name: str, + resource_name: str, + monitor_id: str, + *, + filter: Optional[str] = None, + expand: Optional[str] = None, + start_timestamp_utc: Optional[datetime.datetime] = None, + end_timestamp_utc: Optional[datetime.datetime] = None, + **kwargs: Any +) -> HttpRequest: + api_version = "2020-01-13-preview" + accept = "application/json" + # Construct URL + url = kwargs.pop("template_url", '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history') + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), + "providerName": _SERIALIZER.url("provider_name", provider_name, 'str'), + "resourceCollectionName": _SERIALIZER.url("resource_collection_name", resource_collection_name, 'str'), + "resourceName": _SERIALIZER.url("resource_name", resource_name, 'str'), + "monitorId": _SERIALIZER.url("monitor_id", monitor_id, 'str'), + } + + url = _format_url_section(url, **path_format_arguments) + + # Construct parameters + query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + if filter is not None: + query_parameters['$filter'] = _SERIALIZER.query("filter", filter, 'str') + if expand is not None: + query_parameters['$expand'] = _SERIALIZER.query("expand", expand, 'str') + if start_timestamp_utc is not None: + query_parameters['startTimestampUtc'] = _SERIALIZER.query("start_timestamp_utc", start_timestamp_utc, 'iso-8601') + if end_timestamp_utc is not None: + query_parameters['endTimestampUtc'] = _SERIALIZER.query("end_timestamp_utc", end_timestamp_utc, 'iso-8601') + + # Construct headers + header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=url, + params=query_parameters, + headers=header_parameters, + **kwargs + ) + + +def build_get_state_change_request( + subscription_id: str, + resource_group_name: str, + provider_name: str, + resource_collection_name: str, + resource_name: str, + monitor_id: str, + timestamp_unix: str, + *, + expand: Optional[str] = None, + **kwargs: Any +) -> HttpRequest: + api_version = "2020-01-13-preview" + accept = "application/json" + # Construct URL + url = kwargs.pop("template_url", '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history/{timestampUnix}') + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str'), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str'), + "providerName": _SERIALIZER.url("provider_name", provider_name, 'str'), + "resourceCollectionName": _SERIALIZER.url("resource_collection_name", resource_collection_name, 'str'), + "resourceName": _SERIALIZER.url("resource_name", resource_name, 'str'), + "monitorId": _SERIALIZER.url("monitor_id", monitor_id, 'str'), + "timestampUnix": _SERIALIZER.url("timestamp_unix", timestamp_unix, 'str'), + } + + url = _format_url_section(url, **path_format_arguments) + + # Construct parameters + query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + if expand is not None: + query_parameters['$expand'] = _SERIALIZER.query("expand", expand, 'str') + + # Construct headers + header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=url, + params=query_parameters, + headers=header_parameters, + **kwargs + ) class HealthMonitorsOperations(object): """HealthMonitorsOperations operations. @@ -38,7 +232,7 @@ class HealthMonitorsOperations(object): :param deserializer: An object model deserializer. """ - models = models + models = _models def __init__(self, client, config, serializer, deserializer): self._client = client @@ -46,19 +240,21 @@ def __init__(self, client, config, serializer, deserializer): self._deserialize = deserializer self._config = config + @distributed_trace def list( self, - subscription_id, # type: str - resource_group_name, # type: str - provider_name, # type: str - resource_collection_name, # type: str - resource_name, # type: str - filter=None, # type: Optional[str] - expand=None, # type: Optional[str] - **kwargs # type: Any - ): - # type: (...) -> Iterable["models.HealthMonitorList"] - """Get the current health status of all monitors of a virtual machine. Optional parameters: $expand (retrieve the monitor's evidence and configuration) and $filter (filter by monitor name). + subscription_id: str, + resource_group_name: str, + provider_name: str, + resource_collection_name: str, + resource_name: str, + filter: Optional[str] = None, + expand: Optional[str] = None, + **kwargs: Any + ) -> Iterable["_models.HealthMonitorList"]: + """Get the current health status of all monitors of a virtual machine. Optional parameters: + $expand (retrieve the monitor's evidence and configuration) and $filter (filter by monitor + name). Get the current health status of all monitors of a virtual machine. Optional parameters: $expand (retrieve the monitor's evidence and configuration) and $filter (filter by monitor @@ -75,8 +271,8 @@ def list( :type resource_collection_name: str :param resource_name: The name of the virtual machine. :type resource_name: str - :param filter: Optionally filter by monitor name. Example: $filter=monitorName eq 'logical- - disks|C:|disk-free-space-mb.'. + :param filter: Optionally filter by monitor name. Example: $filter=monitorName eq + 'logical-disks|C:|disk-free-space-mb.'. :type filter: str :param expand: Optionally expand the monitor’s evidence and/or configuration. Example: $expand=evidence,configuration. @@ -86,47 +282,46 @@ def list( :rtype: ~azure.core.paging.ItemPaged[~workload_monitor_api.models.HealthMonitorList] :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.HealthMonitorList"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.HealthMonitorList"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - if not next_link: - # Construct URL - url = self.list.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'providerName': self._serialize.url("provider_name", provider_name, 'str'), - 'resourceCollectionName': self._serialize.url("resource_collection_name", resource_collection_name, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + filter=filter, + expand=expand, + template_url=self.list.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + filter=filter, + expand=expand, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize('HealthMonitorList', pipeline_response) + deserialized = self._deserialize("HealthMonitorList", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) @@ -139,30 +334,32 @@ def get_next(next_link=None): response = pipeline_response.http_response if response.status_code not in [200]: - error = self._deserialize(models.ErrorResponse, response) map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) return pipeline_response + return ItemPaged( get_next, extract_data ) list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors'} # type: ignore + @distributed_trace def get( self, - subscription_id, # type: str - resource_group_name, # type: str - provider_name, # type: str - resource_collection_name, # type: str - resource_name, # type: str - monitor_id, # type: str - expand=None, # type: Optional[str] - **kwargs # type: Any - ): - # type: (...) -> "models.HealthMonitor" - """Get the current health status of a monitor of a virtual machine. Optional parameter: $expand (retrieve the monitor's evidence and configuration). + subscription_id: str, + resource_group_name: str, + provider_name: str, + resource_collection_name: str, + resource_name: str, + monitor_id: str, + expand: Optional[str] = None, + **kwargs: Any + ) -> "_models.HealthMonitor": + """Get the current health status of a monitor of a virtual machine. Optional parameter: $expand + (retrieve the monitor's evidence and configuration). Get the current health status of a monitor of a virtual machine. Optional parameter: $expand (retrieve the monitor's evidence and configuration). @@ -188,43 +385,32 @@ def get( :rtype: ~workload_monitor_api.models.HealthMonitor :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.HealthMonitor"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.HealthMonitor"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - # Construct URL - url = self.get.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'providerName': self._serialize.url("provider_name", provider_name, 'str'), - 'resourceCollectionName': self._serialize.url("resource_collection_name", resource_collection_name, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = build_get_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + monitor_id=monitor_id, + expand=expand, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - request = self._client.get(url, query_parameters, header_parameters) pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(models.ErrorResponse, response) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) deserialized = self._deserialize('HealthMonitor', pipeline_response) @@ -233,24 +419,28 @@ def get( return cls(pipeline_response, deserialized, {}) return deserialized + get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}'} # type: ignore + + @distributed_trace def list_state_changes( self, - subscription_id, # type: str - resource_group_name, # type: str - provider_name, # type: str - resource_collection_name, # type: str - resource_name, # type: str - monitor_id, # type: str - filter=None, # type: Optional[str] - expand=None, # type: Optional[str] - start_timestamp_utc=None, # type: Optional[datetime.datetime] - end_timestamp_utc=None, # type: Optional[datetime.datetime] - **kwargs # type: Any - ): - # type: (...) -> Iterable["models.HealthMonitorStateChangeList"] - """Get the health state changes of a monitor of a virtual machine within the provided time window (default is the last 24 hours). Optional parameters: $expand (retrieve the monitor's evidence and configuration) and $filter (filter by heartbeat condition). + subscription_id: str, + resource_group_name: str, + provider_name: str, + resource_collection_name: str, + resource_name: str, + monitor_id: str, + filter: Optional[str] = None, + expand: Optional[str] = None, + start_timestamp_utc: Optional[datetime.datetime] = None, + end_timestamp_utc: Optional[datetime.datetime] = None, + **kwargs: Any + ) -> Iterable["_models.HealthMonitorStateChangeList"]: + """Get the health state changes of a monitor of a virtual machine within the provided time window + (default is the last 24 hours). Optional parameters: $expand (retrieve the monitor's evidence + and configuration) and $filter (filter by heartbeat condition). Get the health state changes of a monitor of a virtual machine within the provided time window (default is the last 24 hours). Optional parameters: $expand (retrieve the monitor's evidence @@ -279,56 +469,57 @@ def list_state_changes( :param end_timestamp_utc: The end of the time window. :type end_timestamp_utc: ~datetime.datetime :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either HealthMonitorStateChangeList or the result of cls(response) + :return: An iterator like instance of either HealthMonitorStateChangeList or the result of + cls(response) :rtype: ~azure.core.paging.ItemPaged[~workload_monitor_api.models.HealthMonitorStateChangeList] :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.HealthMonitorStateChangeList"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.HealthMonitorStateChangeList"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - if not next_link: - # Construct URL - url = self.list_state_changes.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'providerName': self._serialize.url("provider_name", provider_name, 'str'), - 'resourceCollectionName': self._serialize.url("resource_collection_name", resource_collection_name, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - if start_timestamp_utc is not None: - query_parameters['startTimestampUtc'] = self._serialize.query("start_timestamp_utc", start_timestamp_utc, 'iso-8601') - if end_timestamp_utc is not None: - query_parameters['endTimestampUtc'] = self._serialize.query("end_timestamp_utc", end_timestamp_utc, 'iso-8601') - - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_state_changes_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + monitor_id=monitor_id, + filter=filter, + expand=expand, + start_timestamp_utc=start_timestamp_utc, + end_timestamp_utc=end_timestamp_utc, + template_url=self.list_state_changes.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_state_changes_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + monitor_id=monitor_id, + filter=filter, + expand=expand, + start_timestamp_utc=start_timestamp_utc, + end_timestamp_utc=end_timestamp_utc, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize('HealthMonitorStateChangeList', pipeline_response) + deserialized = self._deserialize("HealthMonitorStateChangeList", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) @@ -341,31 +532,33 @@ def get_next(next_link=None): response = pipeline_response.http_response if response.status_code not in [200]: - error = self._deserialize(models.ErrorResponse, response) map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) return pipeline_response + return ItemPaged( get_next, extract_data ) list_state_changes.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history'} # type: ignore + @distributed_trace def get_state_change( self, - subscription_id, # type: str - resource_group_name, # type: str - provider_name, # type: str - resource_collection_name, # type: str - resource_name, # type: str - monitor_id, # type: str - timestamp_unix, # type: str - expand=None, # type: Optional[str] - **kwargs # type: Any - ): - # type: (...) -> "models.HealthMonitorStateChange" - """Get the health state change of a monitor of a virtual machine at the provided timestamp. Optional parameter: $expand (retrieve the monitor's evidence and configuration). + subscription_id: str, + resource_group_name: str, + provider_name: str, + resource_collection_name: str, + resource_name: str, + monitor_id: str, + timestamp_unix: str, + expand: Optional[str] = None, + **kwargs: Any + ) -> "_models.HealthMonitorStateChange": + """Get the health state change of a monitor of a virtual machine at the provided timestamp. + Optional parameter: $expand (retrieve the monitor's evidence and configuration). Get the health state change of a monitor of a virtual machine at the provided timestamp. Optional parameter: $expand (retrieve the monitor's evidence and configuration). @@ -393,44 +586,33 @@ def get_state_change( :rtype: ~workload_monitor_api.models.HealthMonitorStateChange :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.HealthMonitorStateChange"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.HealthMonitorStateChange"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - # Construct URL - url = self.get_state_change.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'providerName': self._serialize.url("provider_name", provider_name, 'str'), - 'resourceCollectionName': self._serialize.url("resource_collection_name", resource_collection_name, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - 'timestampUnix': self._serialize.url("timestamp_unix", timestamp_unix, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = build_get_state_change_request( + subscription_id=subscription_id, + resource_group_name=resource_group_name, + provider_name=provider_name, + resource_collection_name=resource_collection_name, + resource_name=resource_name, + monitor_id=monitor_id, + timestamp_unix=timestamp_unix, + expand=expand, + template_url=self.get_state_change.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - request = self._client.get(url, query_parameters, header_parameters) pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(models.ErrorResponse, response) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) deserialized = self._deserialize('HealthMonitorStateChange', pipeline_response) @@ -439,4 +621,6 @@ def get_state_change( return cls(pipeline_response, deserialized, {}) return deserialized + get_state_change.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerName}/{resourceCollectionName}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history/{timestampUnix}'} # type: ignore + diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_monitors_operations.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_monitors_operations.py deleted file mode 100644 index 562e3563b5a8..000000000000 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_monitors_operations.py +++ /dev/null @@ -1,429 +0,0 @@ -# coding=utf-8 -# -------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# Code generated by Microsoft (R) AutoRest Code Generator. -# Changes may cause incorrect behavior and will be lost if the code is regenerated. -# -------------------------------------------------------------------------- -import datetime -from typing import TYPE_CHECKING -import warnings - -from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error -from azure.core.paging import ItemPaged -from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpRequest, HttpResponse -from azure.mgmt.core.exceptions import ARMErrorFormat - -from .. import models - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar - - T = TypeVar('T') - ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] - -class MonitorsOperations(object): - """MonitorsOperations operations. - - You should not instantiate this class directly. Instead, you should create a Client instance that - instantiates it for you and attaches it as an attribute. - - :ivar models: Alias to model classes used in this operation group. - :type models: ~workload_monitor_api.models - :param client: Client for service requests. - :param config: Configuration of service client. - :param serializer: An object model serializer. - :param deserializer: An object model deserializer. - """ - - models = models - - def __init__(self, client, config, serializer, deserializer): - self._client = client - self._serialize = serializer - self._deserialize = deserializer - self._config = config - - def list( - self, - subscription_id, # type: str - resource_group_name, # type: str - resource_namespace, # type: str - resource_type, # type: str - resource_name, # type: str - filter=None, # type: Optional[str] - expand=None, # type: Optional[str] - **kwargs # type: Any - ): - # type: (...) -> Iterable["models.MonitorList"] - """Get list of a monitors of a resource (with optional filter). - - Get list of a monitors of a resource (with optional filter). - - :param subscription_id: The subscriptionId of the resource. - :type subscription_id: str - :param resource_group_name: The resourceGroupName of the resource. - :type resource_group_name: str - :param resource_namespace: The resourceNamespace of the resource. - :type resource_namespace: str - :param resource_type: The resourceType of the resource. - :type resource_type: str - :param resource_name: The resourceType of the resource. - :type resource_name: str - :param filter: list example: $filter=monitorName eq 'logical-disks|C:|disk-free-space-mb'; - history example: $filter=isHeartbeat eq false. - :type filter: str - :param expand: ex: $expand=evidence,configuration. - :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MonitorList or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~workload_monitor_api.models.MonitorList] - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MonitorList"] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - if not next_link: - # Construct URL - url = self.list.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'resourceNamespace': self._serialize.url("resource_namespace", resource_namespace, 'str'), - 'resourceType': self._serialize.url("resource_type", resource_type, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - request = self._client.get(url, query_parameters, header_parameters) - else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize('MonitorList', pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - error = self._deserialize(models.DefaultError, response) - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged( - get_next, extract_data - ) - list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors'} # type: ignore - - def get( - self, - subscription_id, # type: str - resource_group_name, # type: str - resource_namespace, # type: str - resource_type, # type: str - resource_name, # type: str - monitor_id, # type: str - expand=None, # type: Optional[str] - **kwargs # type: Any - ): - # type: (...) -> "models.Monitor" - """Get the current status of a monitor of a resource. - - Get the current status of a monitor of a resource. - - :param subscription_id: The subscriptionId of the resource. - :type subscription_id: str - :param resource_group_name: The resourceGroupName of the resource. - :type resource_group_name: str - :param resource_namespace: The resourceNamespace of the resource. - :type resource_namespace: str - :param resource_type: The resourceType of the resource. - :type resource_type: str - :param resource_name: The resourceType of the resource. - :type resource_name: str - :param monitor_id: The monitorId of the resource (url encoded). - :type monitor_id: str - :param expand: ex: $expand=evidence,configuration. - :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: Monitor, or the result of cls(response) - :rtype: ~workload_monitor_api.models.Monitor - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType["models.Monitor"] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - # Construct URL - url = self.get.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'resourceNamespace': self._serialize.url("resource_namespace", resource_namespace, 'str'), - 'resourceType': self._serialize.url("resource_type", resource_type, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - request = self._client.get(url, query_parameters, header_parameters) - pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(models.DefaultError, response) - raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - - deserialized = self._deserialize('Monitor', pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}'} # type: ignore - - def list_state_changes( - self, - subscription_id, # type: str - resource_group_name, # type: str - resource_namespace, # type: str - resource_type, # type: str - resource_name, # type: str - monitor_id, # type: str - filter=None, # type: Optional[str] - expand=None, # type: Optional[str] - start_timestamp_utc=None, # type: Optional[datetime.datetime] - end_timestamp_utc=None, # type: Optional[datetime.datetime] - **kwargs # type: Any - ): - # type: (...) -> Iterable["models.MonitorStateChangeList"] - """Get history of a monitor of a resource (with optional filter). - - Get history of a monitor of a resource (with optional filter). - - :param subscription_id: The subscriptionId of the resource. - :type subscription_id: str - :param resource_group_name: The resourceGroupName of the resource. - :type resource_group_name: str - :param resource_namespace: The resourceNamespace of the resource. - :type resource_namespace: str - :param resource_type: The resourceType of the resource. - :type resource_type: str - :param resource_name: The resourceType of the resource. - :type resource_name: str - :param monitor_id: The monitorId of the resource (url encoded). - :type monitor_id: str - :param filter: list example: $filter=monitorName eq 'logical-disks|C:|disk-free-space-mb'; - history example: $filter=isHeartbeat eq false. - :type filter: str - :param expand: ex: $expand=evidence,configuration. - :type expand: str - :param start_timestamp_utc: The start Timestamp for the desired history. - :type start_timestamp_utc: ~datetime.datetime - :param end_timestamp_utc: The end Timestamp for the desired history. - :type end_timestamp_utc: ~datetime.datetime - :keyword callable cls: A custom type or function that will be passed the direct response - :return: An iterator like instance of either MonitorStateChangeList or the result of cls(response) - :rtype: ~azure.core.paging.ItemPaged[~workload_monitor_api.models.MonitorStateChangeList] - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MonitorStateChangeList"] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - if not next_link: - # Construct URL - url = self.list_state_changes.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'resourceNamespace': self._serialize.url("resource_namespace", resource_namespace, 'str'), - 'resourceType': self._serialize.url("resource_type", resource_type, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if filter is not None: - query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - if start_timestamp_utc is not None: - query_parameters['startTimestampUtc'] = self._serialize.query("start_timestamp_utc", start_timestamp_utc, 'iso-8601') - if end_timestamp_utc is not None: - query_parameters['endTimestampUtc'] = self._serialize.query("end_timestamp_utc", end_timestamp_utc, 'iso-8601') - - request = self._client.get(url, query_parameters, header_parameters) - else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) - return request - - def extract_data(pipeline_response): - deserialized = self._deserialize('MonitorStateChangeList', pipeline_response) - list_of_elem = deserialized.value - if cls: - list_of_elem = cls(list_of_elem) - return deserialized.next_link or None, iter(list_of_elem) - - def get_next(next_link=None): - request = prepare_request(next_link) - - pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - error = self._deserialize(models.DefaultError, response) - map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - - return pipeline_response - - return ItemPaged( - get_next, extract_data - ) - list_state_changes.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history'} # type: ignore - - def get_state_change( - self, - subscription_id, # type: str - resource_group_name, # type: str - resource_namespace, # type: str - resource_type, # type: str - resource_name, # type: str - monitor_id, # type: str - timestamp_unix, # type: str - expand=None, # type: Optional[str] - **kwargs # type: Any - ): - # type: (...) -> "models.MonitorStateChange" - """Get the status of a monitor at a specific timestamp in history. - - Get the status of a monitor at a specific timestamp in history. - - :param subscription_id: The subscriptionId of the resource. - :type subscription_id: str - :param resource_group_name: The resourceGroupName of the resource. - :type resource_group_name: str - :param resource_namespace: The resourceNamespace of the resource. - :type resource_namespace: str - :param resource_type: The resourceType of the resource. - :type resource_type: str - :param resource_name: The resourceType of the resource. - :type resource_name: str - :param monitor_id: The monitorId of the resource (url encoded). - :type monitor_id: str - :param timestamp_unix: The timestamp of the state change (Unix format). - :type timestamp_unix: str - :param expand: ex: $expand=evidence,configuration. - :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: MonitorStateChange, or the result of cls(response) - :rtype: ~workload_monitor_api.models.MonitorStateChange - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType["models.MonitorStateChange"] - error_map = { - 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError - } - error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - - # Construct URL - url = self.get_state_change.metadata['url'] # type: ignore - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'resourceNamespace': self._serialize.url("resource_namespace", resource_namespace, 'str'), - 'resourceType': self._serialize.url("resource_type", resource_type, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str'), - 'monitorId': self._serialize.url("monitor_id", monitor_id, 'str'), - 'timestampUnix': self._serialize.url("timestamp_unix", timestamp_unix, 'str'), - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') - if expand is not None: - query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') - - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - request = self._client.get(url, query_parameters, header_parameters) - pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(models.DefaultError, response) - raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) - - deserialized = self._deserialize('MonitorStateChange', pipeline_response) - - if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized - get_state_change.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/monitors/{monitorId}/history/{timestampUnix}'} # type: ignore diff --git a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_operations.py b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_operations.py index c748c929696b..2e03b6db31ea 100644 --- a/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_operations.py +++ b/sdk/workloadmonitor/azure-mgmt-workloadmonitor/azure/mgmt/workloadmonitor/operations/_operations.py @@ -5,23 +5,50 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import TYPE_CHECKING +import functools +from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar import warnings from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpRequest, HttpResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace from azure.mgmt.core.exceptions import ARMErrorFormat - -from .. import models - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, Iterable, Optional, TypeVar - - T = TypeVar('T') - ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] +from msrest import Serializer + +from .. import models as _models +from .._vendor import _convert_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + +def build_list_request( + **kwargs: Any +) -> HttpRequest: + api_version = "2020-01-13-preview" + accept = "application/json" + # Construct URL + url = kwargs.pop("template_url", '/providers/Microsoft.WorkloadMonitor/operations') + + # Construct parameters + query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=url, + params=query_parameters, + headers=header_parameters, + **kwargs + ) class Operations(object): """Operations operations. @@ -37,7 +64,7 @@ class Operations(object): :param deserializer: An object model deserializer. """ - models = models + models = _models def __init__(self, client, config, serializer, deserializer): self._client = client @@ -45,11 +72,11 @@ def __init__(self, client, config, serializer, deserializer): self._deserialize = deserializer self._config = config + @distributed_trace def list( self, - **kwargs # type: Any - ): - # type: (...) -> Iterable["models.OperationList"] + **kwargs: Any + ) -> Iterable["_models.OperationList"]: """Get a list of all available REST API operations. Get a list of all available REST API operations. @@ -59,35 +86,32 @@ def list( :rtype: ~azure.core.paging.ItemPaged[~workload_monitor_api.models.OperationList] :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.OperationList"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.OperationList"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-01-13-preview" - accept = "application/json" - def prepare_request(next_link=None): - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - if not next_link: - # Construct URL - url = self.list.metadata['url'] # type: ignore - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') + + request = build_list_request( + template_url=self.list.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) - request = self._client.get(url, query_parameters, header_parameters) else: - url = next_link - query_parameters = {} # type: Dict[str, Any] - request = self._client.get(url, query_parameters, header_parameters) + + request = build_list_request( + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" return request def extract_data(pipeline_response): - deserialized = self._deserialize('OperationList', pipeline_response) + deserialized = self._deserialize("OperationList", pipeline_response) list_of_elem = deserialized.value if cls: list_of_elem = cls(list_of_elem) @@ -100,12 +124,13 @@ def get_next(next_link=None): response = pipeline_response.http_response if response.status_code not in [200]: - error = self._deserialize(models.ErrorResponse, response) map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) return pipeline_response + return ItemPaged( get_next, extract_data )