diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/CHANGELOG.md b/sdk/devtestlabs/azure-mgmt-devtestlabs/CHANGELOG.md index 10e9a51a178d..38d006ec12ad 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/CHANGELOG.md +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 10.0.0b2 (2024-11-04) + +### Other Changes + + - Update dependencies + ## 10.0.0b1 (2022-10-28) ### Features Added diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/README.md b/sdk/devtestlabs/azure-mgmt-devtestlabs/README.md index 03cf4a997a7d..2ef870c1232d 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/README.md +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/README.md @@ -1,28 +1,61 @@ # Microsoft Azure SDK for Python This is the Microsoft Azure Dev Test Labs Management Client Library. -This package has been tested with Python 3.7+. +This package has been tested with Python 3.8+. For a more complete view of Azure libraries, see the [azure sdk python release](https://aka.ms/azsdk/python/all). ## _Disclaimer_ _Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer to https://github.com/Azure/azure-sdk-for-python/issues/20691_ -# Usage +## Getting started +### Prerequisites -To learn how to use this package, see the [quickstart guide](https://aka.ms/azsdk/python/mgmt) - -For docs and references, see [Python SDK References](https://docs.microsoft.com/python/api/overview/azure/devtest-labs) -Code samples for this package can be found at [Dev Test Labs Management](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com. -Additional code samples for different Azure services are available at [Samples Repo](https://github.com/Azure-Samples/azure-samples-python-management/tree/main/samples/devtestlabs) +- Python 3.8+ is required to use this package. +- [Azure subscription](https://azure.microsoft.com/free/) +### Install the package -# Provide Feedback +```bash +pip install azure-mgmt-devtestlabs +pip install azure-identity +``` + +### Authentication + +By default, [Azure Active Directory](https://aka.ms/awps/aad) token authentication depends on correct configure of following environment variables. + +- `AZURE_CLIENT_ID` for Azure client ID. +- `AZURE_TENANT_ID` for Azure tenant ID. +- `AZURE_CLIENT_SECRET` for Azure client secret. + +In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`. + +With above configuration, client can be authenticated by following code: + +```python +from azure.identity import DefaultAzureCredential +from azure.mgmt.devtestlabs import DevTestLabsClient +import os + +sub_id = os.getenv("AZURE_SUBSCRIPTION_ID") +client = DevTestLabsClient(credential=DefaultAzureCredential(), subscription_id=sub_id) +``` + +## Examples + +Code samples for this package can be found at: +- [Search Dev Test Labs Management](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com +- [Azure Python Mgmt SDK Samples Repo](https://aka.ms/azsdk/python/mgmt/samples) + + +## Troubleshooting + +## Next steps + +## Provide Feedback If you encounter any bugs or have suggestions, please file an issue in the [Issues](https://github.com/Azure/azure-sdk-for-python/issues) section of the project. - - -![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-mgmt-devtestlabs%2FREADME.png) diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/_meta.json b/sdk/devtestlabs/azure-mgmt-devtestlabs/_meta.json index 6ed8248f7aa3..e6978ba7add5 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/_meta.json +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/_meta.json @@ -1,11 +1,11 @@ { - "commit": "9685ef961fe7931fccdd9bf86afac8bca0b3ae88", + "commit": "cc6315290ff14f03f0c18904a109f82afac4a899", "repository_url": "https://github.com/Azure/azure-rest-api-specs", - "autorest": "3.9.2", + "autorest": "3.10.2", "use": [ - "@autorest/python@6.2.1", - "@autorest/modelerfour@4.24.3" + "@autorest/python@6.19.0", + "@autorest/modelerfour@4.27.0" ], - "autorest_command": "autorest specification/devtestlabs/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/home/vsts/work/1/azure-sdk-for-python/sdk --use=@autorest/python@6.2.1 --use=@autorest/modelerfour@4.24.3 --version=3.9.2 --version-tolerant=False", + "autorest_command": "autorest specification/devtestlabs/resource-manager/readme.md --generate-sample=True --generate-test=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/mnt/vss/_work/1/azure-sdk-for-python/sdk --use=@autorest/python@6.19.0 --use=@autorest/modelerfour@4.27.0 --version=3.10.2 --version-tolerant=False", "readme": "specification/devtestlabs/resource-manager/readme.md" } \ No newline at end of file diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/assets.json b/sdk/devtestlabs/azure-mgmt-devtestlabs/assets.json deleted file mode 100644 index ca36c909d1d6..000000000000 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/assets.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "AssetsRepo": "Azure/azure-sdk-assets", - "AssetsRepoPrefixPath": "python", - "TagPrefix": "python/devtestlabs/azure-mgmt-devtestlabs", - "Tag": "python/devtestlabs/azure-mgmt-devtestlabs_62ee266586" -} diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/__init__.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/__init__.py index 0501481d1dd7..f8340668009b 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/__init__.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/__init__.py @@ -13,7 +13,7 @@ try: from ._patch import __all__ as _patch_all - from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import + from ._patch import * # pylint: disable=unused-wildcard-import except ImportError: _patch_all = [] from ._patch import patch_sdk as _patch_sdk diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_configuration.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_configuration.py index dbb78c1fa93f..5d32cad1db16 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_configuration.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_configuration.py @@ -6,26 +6,19 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import sys from typing import Any, TYPE_CHECKING -from azure.core.configuration import Configuration from azure.core.pipeline import policies from azure.mgmt.core.policies import ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy from ._version import VERSION -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports -else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports - if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials import TokenCredential -class DevTestLabsClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes +class DevTestLabsClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long """Configuration for DevTestLabsClient. Note that all parameters used to create this instance are saved as instance @@ -41,8 +34,7 @@ class DevTestLabsClientConfiguration(Configuration): # pylint: disable=too-many """ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs: Any) -> None: - super(DevTestLabsClientConfiguration, self).__init__(**kwargs) - api_version = kwargs.pop("api_version", "2018-09-15") # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", "2018-09-15") if credential is None: raise ValueError("Parameter 'credential' must not be None.") @@ -54,20 +46,18 @@ def __init__(self, credential: "TokenCredential", subscription_id: str, **kwargs self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-devtestlabs/{}".format(VERSION)) + self.polling_interval = kwargs.get("polling_interval", 30) self._configure(**kwargs) - def _configure( - self, **kwargs # type: Any - ): - # type: (...) -> None + def _configure(self, **kwargs: Any) -> None: self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) self.http_logging_policy = kwargs.get("http_logging_policy") or ARMHttpLoggingPolicy(**kwargs) - self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) self.authentication_policy = kwargs.get("authentication_policy") if self.credential and not self.authentication_policy: self.authentication_policy = ARMChallengeAuthenticationPolicy( diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_dev_test_labs_client.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_dev_test_labs_client.py index be2b029c11ce..9a63f3e6cf24 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_dev_test_labs_client.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_dev_test_labs_client.py @@ -8,11 +8,14 @@ from copy import deepcopy from typing import Any, TYPE_CHECKING +from typing_extensions import Self +from azure.core.pipeline import policies from azure.core.rest import HttpRequest, HttpResponse from azure.mgmt.core import ARMPipelineClient +from azure.mgmt.core.policies import ARMAutoResourceProviderRegistrationPolicy -from . import models +from . import models as _models from ._configuration import DevTestLabsClientConfiguration from ._serialization import Deserializer, Serializer from .operations import ( @@ -125,9 +128,27 @@ def __init__( **kwargs: Any ) -> None: self._config = DevTestLabsClientConfiguration(credential=credential, subscription_id=subscription_id, **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)} + _policies = kwargs.pop("policies", None) + if _policies is None: + _policies = [ + policies.RequestIdPolicy(**kwargs), + self._config.headers_policy, + self._config.user_agent_policy, + self._config.proxy_policy, + policies.ContentDecodePolicy(**kwargs), + ARMAutoResourceProviderRegistrationPolicy(), + self._config.redirect_policy, + self._config.retry_policy, + self._config.authentication_policy, + self._config.custom_hook_policy, + self._config.logging_policy, + policies.DistributedTracingPolicy(**kwargs), + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, + self._config.http_logging_policy, + ] + self._client: ARMPipelineClient = ARMPipelineClient(base_url=base_url, policies=_policies, **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 @@ -173,7 +194,7 @@ def __init__( self._client, self._config, self._serialize, self._deserialize ) - def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: + def _send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest @@ -193,17 +214,14 @@ def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: request_copy = deepcopy(request) request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore - def close(self): - # type: () -> None + def close(self) -> None: self._client.close() - def __enter__(self): - # type: () -> DevTestLabsClient + def __enter__(self) -> Self: self._client.__enter__() return self - def __exit__(self, *exc_details): - # type: (Any) -> None + def __exit__(self, *exc_details: Any) -> None: self._client.__exit__(*exc_details) diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_serialization.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_serialization.py index 7c1dedb5133d..8139854b97bb 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_serialization.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_serialization.py @@ -25,6 +25,7 @@ # -------------------------------------------------------------------------- # pylint: skip-file +# pyright: reportUnnecessaryTypeIgnoreComment=false from base64 import b64decode, b64encode import calendar @@ -37,23 +38,38 @@ import re import sys import codecs +from typing import ( + Dict, + Any, + cast, + Optional, + Union, + AnyStr, + IO, + Mapping, + Callable, + TypeVar, + MutableMapping, + Type, + List, + Mapping, +) try: from urllib import quote # type: ignore except ImportError: - from urllib.parse import quote # type: ignore + from urllib.parse import quote import xml.etree.ElementTree as ET -import isodate +import isodate # type: ignore -from typing import Dict, Any, cast, TYPE_CHECKING - -from azure.core.exceptions import DeserializationError, SerializationError, raise_with_traceback +from azure.core.exceptions import DeserializationError, SerializationError +from azure.core.serialization import NULL as CoreNull _BOM = codecs.BOM_UTF8.decode(encoding="utf-8") -if TYPE_CHECKING: - from typing import Optional, Union, AnyStr, IO, Mapping +ModelType = TypeVar("ModelType", bound="Model") +JSON = MutableMapping[str, Any] class RawDeserializer: @@ -65,8 +81,7 @@ class RawDeserializer: CONTEXT_NAME = "deserialized_data" @classmethod - def deserialize_from_text(cls, data, content_type=None): - # type: (Optional[Union[AnyStr, IO]], Optional[str]) -> Any + def deserialize_from_text(cls, data: Optional[Union[AnyStr, IO]], content_type: Optional[str] = None) -> Any: """Decode data according to content-type. Accept a stream of data as well, but will be load at once in memory for now. @@ -109,7 +124,7 @@ def deserialize_from_text(cls, data, content_type=None): pass return ET.fromstring(data_as_str) # nosec - except ET.ParseError: + except ET.ParseError as err: # It might be because the server has an issue, and returned JSON with # content-type XML.... # So let's try a JSON load, and if it's still broken @@ -128,12 +143,13 @@ def _json_attemp(data): # The function hack is because Py2.7 messes up with exception # context otherwise. _LOGGER.critical("Wasn't XML not JSON, failing") - raise_with_traceback(DeserializationError, "XML is invalid") + raise DeserializationError("XML is invalid") from err + elif content_type.startswith("text/"): + return data_as_str raise DeserializationError("Cannot deserialize content-type: {}".format(content_type)) @classmethod - def deserialize_from_http_generics(cls, body_bytes, headers): - # type: (Optional[Union[AnyStr, IO]], Mapping) -> Any + def deserialize_from_http_generics(cls, body_bytes: Optional[Union[AnyStr, IO]], headers: Mapping) -> Any: """Deserialize from HTTP response. Use bytes and headers to NOT use any requests/aiohttp or whatever @@ -156,13 +172,6 @@ def deserialize_from_http_generics(cls, body_bytes, headers): return None -try: - basestring # type: ignore - unicode_str = unicode # type: ignore -except NameError: - basestring = str # type: ignore - unicode_str = str # type: ignore - _LOGGER = logging.getLogger(__name__) try: @@ -188,7 +197,7 @@ def dst(self, dt): try: - from datetime import timezone as _FixedOffset + from datetime import timezone as _FixedOffset # type: ignore except ImportError: # Python 2.7 class _FixedOffset(datetime.tzinfo): # type: ignore @@ -219,7 +228,7 @@ def __getinitargs__(self): try: from datetime import timezone - TZ_UTC = timezone.utc # type: ignore + TZ_UTC = timezone.utc except ImportError: TZ_UTC = UTC() # type: ignore @@ -276,12 +285,12 @@ class Model(object): serialization and deserialization. """ - _subtype_map = {} # type: Dict[str, Dict[str, Any]] - _attribute_map = {} # type: Dict[str, Dict[str, Any]] - _validation = {} # type: Dict[str, Dict[str, Any]] + _subtype_map: Dict[str, Dict[str, Any]] = {} + _attribute_map: Dict[str, Dict[str, Any]] = {} + _validation: Dict[str, Dict[str, Any]] = {} - def __init__(self, **kwargs): - self.additional_properties = {} + def __init__(self, **kwargs: Any) -> None: + self.additional_properties: Optional[Dict[str, Any]] = {} for k in kwargs: if k not in self._attribute_map: _LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__) @@ -290,27 +299,27 @@ def __init__(self, **kwargs): else: setattr(self, k, kwargs[k]) - def __eq__(self, other): + def __eq__(self, other: Any) -> bool: """Compare objects by comparing all attributes.""" if isinstance(other, self.__class__): return self.__dict__ == other.__dict__ return False - def __ne__(self, other): + def __ne__(self, other: Any) -> bool: """Compare objects by comparing all attributes.""" return not self.__eq__(other) - def __str__(self): + def __str__(self) -> str: return str(self.__dict__) @classmethod - def enable_additional_properties_sending(cls): + def enable_additional_properties_sending(cls) -> None: cls._attribute_map["additional_properties"] = {"key": "", "type": "{object}"} @classmethod - def is_xml_model(cls): + def is_xml_model(cls) -> bool: try: - cls._xml_map + cls._xml_map # type: ignore except AttributeError: return False return True @@ -319,14 +328,14 @@ def is_xml_model(cls): def _create_xml_node(cls): """Create XML node.""" try: - xml_map = cls._xml_map + xml_map = cls._xml_map # type: ignore except AttributeError: xml_map = {} return _create_xml_node(xml_map.get("name", cls.__name__), xml_map.get("prefix", None), xml_map.get("ns", None)) - def serialize(self, keep_readonly=False, **kwargs): - """Return the JSON that would be sent to azure from this model. + def serialize(self, keep_readonly: bool = False, **kwargs: Any) -> JSON: + """Return the JSON that would be sent to server from this model. This is an alias to `as_dict(full_restapi_key_transformer, keep_readonly=False)`. @@ -337,10 +346,15 @@ def serialize(self, keep_readonly=False, **kwargs): :rtype: dict """ serializer = Serializer(self._infer_class_models()) - return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) + return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) # type: ignore - def as_dict(self, keep_readonly=True, key_transformer=attribute_transformer, **kwargs): - """Return a dict that can be JSONify using json.dump. + def as_dict( + self, + keep_readonly: bool = True, + key_transformer: Callable[[str, Dict[str, Any], Any], Any] = attribute_transformer, + **kwargs: Any + ) -> JSON: + """Return a dict that can be serialized using json.dump. Advanced usage might optionally use a callback as parameter: @@ -371,7 +385,7 @@ def my_key_transformer(key, attr_desc, value): :rtype: dict """ serializer = Serializer(self._infer_class_models()) - return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) + return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) # type: ignore @classmethod def _infer_class_models(cls): @@ -387,7 +401,7 @@ def _infer_class_models(cls): return client_models @classmethod - def deserialize(cls, data, content_type=None): + def deserialize(cls: Type[ModelType], data: Any, content_type: Optional[str] = None) -> ModelType: """Parse a str using the RestAPI syntax and return a model. :param str data: A str using RestAPI structure. JSON by default. @@ -396,10 +410,15 @@ def deserialize(cls, data, content_type=None): :raises: DeserializationError if something went wrong """ deserializer = Deserializer(cls._infer_class_models()) - return deserializer(cls.__name__, data, content_type=content_type) + return deserializer(cls.__name__, data, content_type=content_type) # type: ignore @classmethod - def from_dict(cls, data, key_extractors=None, content_type=None): + def from_dict( + cls: Type[ModelType], + data: Any, + key_extractors: Optional[Callable[[str, Dict[str, Any], Any], Any]] = None, + content_type: Optional[str] = None, + ) -> ModelType: """Parse a dict using given key extractor return a model. By default consider key @@ -412,8 +431,8 @@ def from_dict(cls, data, key_extractors=None, content_type=None): :raises: DeserializationError if something went wrong """ deserializer = Deserializer(cls._infer_class_models()) - deserializer.key_extractors = ( - [ + deserializer.key_extractors = ( # type: ignore + [ # type: ignore attribute_key_case_insensitive_extractor, rest_key_case_insensitive_extractor, last_rest_key_case_insensitive_extractor, @@ -421,7 +440,7 @@ def from_dict(cls, data, key_extractors=None, content_type=None): if key_extractors is None else key_extractors ) - return deserializer(cls.__name__, data, content_type=content_type) + return deserializer(cls.__name__, data, content_type=content_type) # type: ignore @classmethod def _flatten_subtype(cls, key, objects): @@ -453,7 +472,7 @@ def _classify(cls, response, objects): return cls flatten_mapping_type = cls._flatten_subtype(subtype_key, objects) try: - return objects[flatten_mapping_type[subtype_value]] + return objects[flatten_mapping_type[subtype_value]] # type: ignore except KeyError: _LOGGER.warning( "Subtype value %s has no mapping, use base class %s.", @@ -521,7 +540,7 @@ class Serializer(object): "multiple": lambda x, y: x % y != 0, } - def __init__(self, classes=None): + def __init__(self, classes: Optional[Mapping[str, type]] = None): self.serialize_type = { "iso-8601": Serializer.serialize_iso, "rfc-1123": Serializer.serialize_rfc, @@ -537,7 +556,7 @@ def __init__(self, classes=None): "[]": self.serialize_iter, "{}": self.serialize_dict, } - self.dependencies = dict(classes) if classes else {} + self.dependencies: Dict[str, type] = dict(classes) if classes else {} self.key_transformer = full_restapi_key_transformer self.client_side_validation = True @@ -605,14 +624,14 @@ def _serialize(self, target_obj, data_type=None, **kwargs): if xml_desc.get("attr", False): if xml_ns: ET.register_namespace(xml_prefix, xml_ns) - xml_name = "{}{}".format(xml_ns, xml_name) - serialized.set(xml_name, new_attr) + xml_name = "{{{}}}{}".format(xml_ns, xml_name) + serialized.set(xml_name, new_attr) # type: ignore continue if xml_desc.get("text", False): - serialized.text = new_attr + serialized.text = new_attr # type: ignore continue if isinstance(new_attr, list): - serialized.extend(new_attr) + serialized.extend(new_attr) # type: ignore elif isinstance(new_attr, ET.Element): # If the down XML has no XML/Name, we MUST replace the tag with the local tag. But keeping the namespaces. if "name" not in getattr(orig_attr, "_xml_map", {}): @@ -621,30 +640,30 @@ def _serialize(self, target_obj, data_type=None, **kwargs): new_attr.tag = "}".join([splitted_tag[0], xml_name]) else: new_attr.tag = xml_name - serialized.append(new_attr) + serialized.append(new_attr) # type: ignore else: # That's a basic type # Integrate namespace if necessary local_node = _create_xml_node(xml_name, xml_prefix, xml_ns) - local_node.text = unicode_str(new_attr) - serialized.append(local_node) + local_node.text = str(new_attr) + serialized.append(local_node) # type: ignore else: # JSON - for k in reversed(keys): - unflattened = {k: new_attr} - new_attr = unflattened + for k in reversed(keys): # type: ignore + new_attr = {k: new_attr} _new_attr = new_attr _serialized = serialized - for k in keys: + for k in keys: # type: ignore if k not in _serialized: - _serialized.update(_new_attr) - _new_attr = _new_attr[k] + _serialized.update(_new_attr) # type: ignore + _new_attr = _new_attr[k] # type: ignore _serialized = _serialized[k] - except ValueError: - continue + except ValueError as err: + if isinstance(err, SerializationError): + raise except (AttributeError, KeyError, TypeError) as err: msg = "Attribute {} in object {} cannot be serialized.\n{}".format(attr_name, class_name, str(target_obj)) - raise_with_traceback(SerializationError, msg, err) + raise SerializationError(msg) from err else: return serialized @@ -659,8 +678,8 @@ def body(self, data, data_type, **kwargs): """ # Just in case this is a dict - internal_data_type = data_type.strip("[]{}") - internal_data_type = self.dependencies.get(internal_data_type, None) + internal_data_type_str = data_type.strip("[]{}") + internal_data_type = self.dependencies.get(internal_data_type_str, None) try: is_xml_model_serialization = kwargs["is_xml"] except KeyError: @@ -675,7 +694,7 @@ def body(self, data, data_type, **kwargs): # We're not able to deal with additional properties for now. deserializer.additional_properties_detection = False if is_xml_model_serialization: - deserializer.key_extractors = [ + deserializer.key_extractors = [ # type: ignore attribute_key_case_insensitive_extractor, ] else: @@ -686,7 +705,7 @@ def body(self, data, data_type, **kwargs): ] data = deserializer._deserialize(data_type, data) except DeserializationError as err: - raise_with_traceback(SerializationError, "Unable to build a model: " + str(err), err) + raise SerializationError("Unable to build a model: " + str(err)) from err return self._serialize(data, data_type, **kwargs) @@ -706,6 +725,7 @@ def url(self, name, data, data_type, **kwargs): if kwargs.get("skip_quote") is True: output = str(output) + output = output.replace("{", quote("{")).replace("}", quote("}")) else: output = quote(str(output), safe="") except SerializationError: @@ -718,7 +738,9 @@ def query(self, name, data, data_type, **kwargs): :param data: The data to be serialized. :param str data_type: The type to be serialized from. - :rtype: str + :keyword bool skip_quote: Whether to skip quote the serialized result. + Defaults to False. + :rtype: str, list :raises: TypeError if serialization fails. :raises: ValueError if data is None """ @@ -726,10 +748,8 @@ def query(self, name, data, data_type, **kwargs): # Treat the list aside, since we don't want to encode the div separator if data_type.startswith("["): internal_data_type = data_type[1:-1] - data = [self.serialize_data(d, internal_data_type, **kwargs) if d is not None else "" for d in data] - if not kwargs.get("skip_quote", False): - data = [quote(str(d), safe="") for d in data] - return str(self.serialize_iter(data, internal_data_type, **kwargs)) + do_quote = not kwargs.get("skip_quote", False) + return self.serialize_iter(data, internal_data_type, do_quote=do_quote, **kwargs) # Not a list, regular serialization output = self.serialize_data(data, data_type, **kwargs) @@ -780,6 +800,8 @@ def serialize_data(self, data, data_type, **kwargs): raise ValueError("No value for given attribute") try: + if data is CoreNull: + return None if data_type in self.basic_types.values(): return self.serialize_basic(data, data_type, **kwargs) @@ -798,7 +820,7 @@ def serialize_data(self, data, data_type, **kwargs): except (ValueError, TypeError) as err: msg = "Unable to serialize value: {!r} as type: {!r}." - raise_with_traceback(SerializationError, msg.format(data, data_type), err) + raise SerializationError(msg.format(data, data_type)) from err else: return self._serialize(data, **kwargs) @@ -843,7 +865,7 @@ def serialize_unicode(cls, data): pass try: - if isinstance(data, unicode): + if isinstance(data, unicode): # type: ignore # Don't change it, JSON and XML ElementTree are totally able # to serialize correctly u'' strings return data @@ -866,6 +888,8 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs): not be None or empty. :param str div: If set, this str will be used to combine the elements in the iterable into a combined string. Default is 'None'. + :keyword bool do_quote: Whether to quote the serialized result of each iterable element. + Defaults to False. :rtype: list, str """ if isinstance(data, str): @@ -878,9 +902,14 @@ def serialize_iter(self, data, iter_type, div=None, **kwargs): for d in data: try: serialized.append(self.serialize_data(d, iter_type, **kwargs)) - except ValueError: + except ValueError as err: + if isinstance(err, SerializationError): + raise serialized.append(None) + if kwargs.get("do_quote", False): + serialized = ["" if s is None else quote(str(s), safe="") for s in serialized] + if div: serialized = ["" if s is None else str(s) for s in serialized] serialized = div.join(serialized) @@ -925,7 +954,9 @@ def serialize_dict(self, attr, dict_type, **kwargs): for key, value in attr.items(): try: serialized[self.serialize_unicode(key)] = self.serialize_data(value, dict_type, **kwargs) - except ValueError: + except ValueError as err: + if isinstance(err, SerializationError): + raise serialized[self.serialize_unicode(key)] = None if "xml" in serialization_ctxt: @@ -958,7 +989,7 @@ def serialize_object(self, attr, **kwargs): return self.serialize_basic(attr, self.basic_types[obj_type], **kwargs) if obj_type is _long_type: return self.serialize_long(attr) - if obj_type is unicode_str: + if obj_type is str: return self.serialize_unicode(attr) if obj_type is datetime.datetime: return self.serialize_iso(attr) @@ -1001,10 +1032,10 @@ def serialize_enum(attr, enum_obj=None): except AttributeError: result = attr try: - enum_obj(result) + enum_obj(result) # type: ignore return result except ValueError: - for enum_value in enum_obj: + for enum_value in enum_obj: # type: ignore if enum_value.value.lower() == str(attr).lower(): return enum_value.value error = "{!r} is not valid value for enum {!r}" @@ -1135,10 +1166,10 @@ def serialize_iso(attr, **kwargs): return date + microseconds + "Z" except (ValueError, OverflowError) as err: msg = "Unable to serialize datetime object." - raise_with_traceback(SerializationError, msg, err) + raise SerializationError(msg) from err except AttributeError as err: msg = "ISO-8601 object must be valid Datetime object." - raise_with_traceback(TypeError, msg, err) + raise TypeError(msg) from err @staticmethod def serialize_unix(attr, **kwargs): @@ -1164,7 +1195,8 @@ def rest_key_extractor(attr, attr_desc, data): working_data = data while "." in key: - dict_keys = _FLATTEN.split(key) + # Need the cast, as for some reasons "split" is typed as list[str | Any] + dict_keys = cast(List[str], _FLATTEN.split(key)) if len(dict_keys) == 1: key = _decode_attribute_map_key(dict_keys[0]) break @@ -1173,7 +1205,6 @@ def rest_key_extractor(attr, attr_desc, data): if working_data is None: # If at any point while following flatten JSON path see None, it means # that all properties under are None as well - # https://github.com/Azure/msrest-for-python/issues/197 return None key = ".".join(dict_keys[1:]) @@ -1194,7 +1225,6 @@ def rest_key_case_insensitive_extractor(attr, attr_desc, data): if working_data is None: # If at any point while following flatten JSON path see None, it means # that all properties under are None as well - # https://github.com/Azure/msrest-for-python/issues/197 return None key = ".".join(dict_keys[1:]) @@ -1245,7 +1275,7 @@ def _extract_name_from_internal_type(internal_type): xml_name = internal_type_xml_map.get("name", internal_type.__name__) xml_ns = internal_type_xml_map.get("ns", None) if xml_ns: - xml_name = "{}{}".format(xml_ns, xml_name) + xml_name = "{{{}}}{}".format(xml_ns, xml_name) return xml_name @@ -1269,7 +1299,7 @@ def xml_key_extractor(attr, attr_desc, data): # Integrate namespace if necessary xml_ns = xml_desc.get("ns", internal_type_xml_map.get("ns", None)) if xml_ns: - xml_name = "{}{}".format(xml_ns, xml_name) + xml_name = "{{{}}}{}".format(xml_ns, xml_name) # If it's an attribute, that's simple if xml_desc.get("attr", False): @@ -1335,7 +1365,7 @@ class Deserializer(object): valid_date = re.compile(r"\d{4}[-]\d{2}[-]\d{2}T\d{2}:\d{2}:\d{2}" r"\.?\d*Z?[-+]?[\d{2}]?:?[\d{2}]?") - def __init__(self, classes=None): + def __init__(self, classes: Optional[Mapping[str, type]] = None): self.deserialize_type = { "iso-8601": Deserializer.deserialize_iso, "rfc-1123": Deserializer.deserialize_rfc, @@ -1355,7 +1385,7 @@ def __init__(self, classes=None): "duration": (isodate.Duration, datetime.timedelta), "iso-8601": (datetime.datetime), } - self.dependencies = dict(classes) if classes else {} + self.dependencies: Dict[str, type] = dict(classes) if classes else {} self.key_extractors = [rest_key_extractor, xml_key_extractor] # Additional properties only works if the "rest_key_extractor" is used to # extract the keys. Making it to work whatever the key extractor is too much @@ -1408,15 +1438,15 @@ def _deserialize(self, target_obj, data): response, class_name = self._classify_target(target_obj, data) - if isinstance(response, basestring): + if isinstance(response, str): return self.deserialize_data(data, response) elif isinstance(response, type) and issubclass(response, Enum): return self.deserialize_enum(data, response) - if data is None: + if data is None or data is CoreNull: return data try: - attributes = response._attribute_map + attributes = response._attribute_map # type: ignore d_attrs = {} for attr, attr_desc in attributes.items(): # Check empty string. If it's not empty, someone has a real "additionalProperties"... @@ -1444,8 +1474,8 @@ def _deserialize(self, target_obj, data): value = self.deserialize_data(raw_value, attr_desc["type"]) d_attrs[attr] = value except (AttributeError, TypeError, KeyError) as err: - msg = "Unable to deserialize to object: " + class_name - raise_with_traceback(DeserializationError, msg, err) + msg = "Unable to deserialize to object: " + class_name # type: ignore + raise DeserializationError(msg) from err else: additional_properties = self._build_additional_properties(attributes, data) return self._instantiate_model(response, d_attrs, additional_properties) @@ -1474,22 +1504,22 @@ def _classify_target(self, target, data): Once classification has been determined, initialize object. :param str target: The target object type to deserialize to. - :param str/dict data: The response data to deseralize. + :param str/dict data: The response data to deserialize. """ if target is None: return None, None - if isinstance(target, basestring): + if isinstance(target, str): try: target = self.dependencies[target] except KeyError: return target, target try: - target = target._classify(data, self.dependencies) + target = target._classify(data, self.dependencies) # type: ignore except AttributeError: pass # Target is not a Model, no classify - return target, target.__class__.__name__ + return target, target.__class__.__name__ # type: ignore def failsafe_deserialize(self, target_obj, data, content_type=None): """Ignores any errors encountered in deserialization, @@ -1499,7 +1529,7 @@ def failsafe_deserialize(self, target_obj, data, content_type=None): a deserialization error. :param str target_obj: The target object type to deserialize to. - :param str/dict data: The response data to deseralize. + :param str/dict data: The response data to deserialize. :param str content_type: Swagger "produces" if available. """ try: @@ -1542,8 +1572,8 @@ def _unpack_content(raw_data, content_type=None): if hasattr(raw_data, "_content_consumed"): return RawDeserializer.deserialize_from_http_generics(raw_data.text, raw_data.headers) - if isinstance(raw_data, (basestring, bytes)) or hasattr(raw_data, "read"): - return RawDeserializer.deserialize_from_text(raw_data, content_type) + if isinstance(raw_data, (str, bytes)) or hasattr(raw_data, "read"): + return RawDeserializer.deserialize_from_text(raw_data, content_type) # type: ignore return raw_data def _instantiate_model(self, response, attrs, additional_properties=None): @@ -1565,7 +1595,7 @@ def _instantiate_model(self, response, attrs, additional_properties=None): response_obj.additional_properties = additional_properties return response_obj except TypeError as err: - msg = "Unable to deserialize {} into model {}. ".format(kwargs, response) + msg = "Unable to deserialize {} into model {}. ".format(kwargs, response) # type: ignore raise DeserializationError(msg + str(err)) else: try: @@ -1616,7 +1646,7 @@ def deserialize_data(self, data, data_type): except (ValueError, TypeError, AttributeError) as err: msg = "Unable to deserialize response data." msg += " Data: {}, {}".format(data, data_type) - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return self._deserialize(obj_type, data) @@ -1664,7 +1694,7 @@ def deserialize_object(self, attr, **kwargs): if isinstance(attr, ET.Element): # Do no recurse on XML, just return the tree as-is return attr - if isinstance(attr, basestring): + if isinstance(attr, str): return self.deserialize_basic(attr, "str") obj_type = type(attr) if obj_type in self.basic_types: @@ -1721,7 +1751,7 @@ def deserialize_basic(self, attr, data_type): if data_type == "bool": if attr in [True, False, 1, 0]: return bool(attr) - elif isinstance(attr, basestring): + elif isinstance(attr, str): if attr.lower() in ["true", "1"]: return True elif attr.lower() in ["false", "0"]: @@ -1747,7 +1777,7 @@ def deserialize_unicode(data): # Consider this is real string try: - if isinstance(data, unicode): + if isinstance(data, unicode): # type: ignore return data except NameError: return str(data) @@ -1772,7 +1802,6 @@ def deserialize_enum(data, enum_obj): data = data.value if isinstance(data, int): # Workaround. We might consider remove it in the future. - # https://github.com/Azure/azure-rest-api-specs/issues/141 try: return list(enum_obj.__members__.values())[data] except IndexError: @@ -1798,7 +1827,7 @@ def deserialize_bytearray(attr): """ if isinstance(attr, ET.Element): attr = attr.text - return bytearray(b64decode(attr)) + return bytearray(b64decode(attr)) # type: ignore @staticmethod def deserialize_base64(attr): @@ -1810,8 +1839,8 @@ def deserialize_base64(attr): """ if isinstance(attr, ET.Element): attr = attr.text - padding = "=" * (3 - (len(attr) + 3) % 4) - attr = attr + padding + padding = "=" * (3 - (len(attr) + 3) % 4) # type: ignore + attr = attr + padding # type: ignore encoded = attr.replace("-", "+").replace("_", "/") return b64decode(encoded) @@ -1826,10 +1855,10 @@ def deserialize_decimal(attr): if isinstance(attr, ET.Element): attr = attr.text try: - return decimal.Decimal(attr) + return decimal.Decimal(str(attr)) # type: ignore except decimal.DecimalException as err: msg = "Invalid decimal {}".format(attr) - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err @staticmethod def deserialize_long(attr): @@ -1841,7 +1870,7 @@ def deserialize_long(attr): """ if isinstance(attr, ET.Element): attr = attr.text - return _long_type(attr) + return _long_type(attr) # type: ignore @staticmethod def deserialize_duration(attr): @@ -1857,7 +1886,7 @@ def deserialize_duration(attr): duration = isodate.parse_duration(attr) except (ValueError, OverflowError, AttributeError) as err: msg = "Cannot deserialize duration object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return duration @@ -1871,10 +1900,10 @@ def deserialize_date(attr): """ if isinstance(attr, ET.Element): attr = attr.text - if re.search(r"[^\W\d_]", attr, re.I + re.U): + if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore raise DeserializationError("Date must have only digits and -. Received: %s" % attr) # This must NOT use defaultmonth/defaultday. Using None ensure this raises an exception. - return isodate.parse_date(attr, defaultmonth=None, defaultday=None) + return isodate.parse_date(attr, defaultmonth=0, defaultday=0) @staticmethod def deserialize_time(attr): @@ -1886,7 +1915,7 @@ def deserialize_time(attr): """ if isinstance(attr, ET.Element): attr = attr.text - if re.search(r"[^\W\d_]", attr, re.I + re.U): + if re.search(r"[^\W\d_]", attr, re.I + re.U): # type: ignore raise DeserializationError("Date must have only digits and -. Received: %s" % attr) return isodate.parse_time(attr) @@ -1901,7 +1930,7 @@ def deserialize_rfc(attr): if isinstance(attr, ET.Element): attr = attr.text try: - parsed_date = email.utils.parsedate_tz(attr) + parsed_date = email.utils.parsedate_tz(attr) # type: ignore date_obj = datetime.datetime( *parsed_date[:6], tzinfo=_FixedOffset(datetime.timedelta(minutes=(parsed_date[9] or 0) / 60)) ) @@ -1909,7 +1938,7 @@ def deserialize_rfc(attr): date_obj = date_obj.astimezone(tz=TZ_UTC) except ValueError as err: msg = "Cannot deserialize to rfc datetime object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return date_obj @@ -1924,7 +1953,7 @@ def deserialize_iso(attr): if isinstance(attr, ET.Element): attr = attr.text try: - attr = attr.upper() + attr = attr.upper() # type: ignore match = Deserializer.valid_date.match(attr) if not match: raise ValueError("Invalid datetime string: " + attr) @@ -1946,7 +1975,7 @@ def deserialize_iso(attr): raise OverflowError("Hit max or min date") except (ValueError, OverflowError, AttributeError) as err: msg = "Cannot deserialize datetime object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return date_obj @@ -1960,11 +1989,12 @@ def deserialize_unix(attr): :raises: DeserializationError if format invalid """ if isinstance(attr, ET.Element): - attr = int(attr.text) + attr = int(attr.text) # type: ignore try: + attr = int(attr) date_obj = datetime.datetime.fromtimestamp(attr, TZ_UTC) except ValueError as err: msg = "Cannot deserialize to unix datetime object." - raise_with_traceback(DeserializationError, msg, err) + raise DeserializationError(msg) from err else: return date_obj diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_vendor.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_vendor.py deleted file mode 100644 index 9aad73fc743e..000000000000 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_vendor.py +++ /dev/null @@ -1,27 +0,0 @@ -# -------------------------------------------------------------------------- -# 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/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_version.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_version.py index 79aaa33e5e04..1b3a42bc5995 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_version.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "10.0.0b1" +VERSION = "10.0.0b2" diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/__init__.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/__init__.py index 9b937368c67d..c1da859932b1 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/__init__.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/__init__.py @@ -10,7 +10,7 @@ try: from ._patch import __all__ as _patch_all - from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import + from ._patch import * # pylint: disable=unused-wildcard-import except ImportError: _patch_all = [] from ._patch import patch_sdk as _patch_sdk diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/_configuration.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/_configuration.py index 92c6b4daadbd..16d75484d073 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/_configuration.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/_configuration.py @@ -6,26 +6,19 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import sys 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, AsyncARMChallengeAuthenticationPolicy from .._version import VERSION -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports -else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports - if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports from azure.core.credentials_async import AsyncTokenCredential -class DevTestLabsClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes +class DevTestLabsClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long """Configuration for DevTestLabsClient. Note that all parameters used to create this instance are saved as instance @@ -41,8 +34,7 @@ class DevTestLabsClientConfiguration(Configuration): # pylint: disable=too-many """ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **kwargs: Any) -> None: - super(DevTestLabsClientConfiguration, self).__init__(**kwargs) - api_version = kwargs.pop("api_version", "2018-09-15") # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", "2018-09-15") if credential is None: raise ValueError("Parameter 'credential' must not be None.") @@ -54,6 +46,7 @@ def __init__(self, credential: "AsyncTokenCredential", subscription_id: str, **k self.api_version = api_version self.credential_scopes = kwargs.pop("credential_scopes", ["https://management.azure.com/.default"]) kwargs.setdefault("sdk_moniker", "mgmt-devtestlabs/{}".format(VERSION)) + self.polling_interval = kwargs.get("polling_interval", 30) self._configure(**kwargs) def _configure(self, **kwargs: Any) -> None: @@ -62,9 +55,9 @@ def _configure(self, **kwargs: Any) -> None: self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) self.http_logging_policy = kwargs.get("http_logging_policy") or ARMHttpLoggingPolicy(**kwargs) - self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) self.authentication_policy = kwargs.get("authentication_policy") if self.credential and not self.authentication_policy: self.authentication_policy = AsyncARMChallengeAuthenticationPolicy( diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/_dev_test_labs_client.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/_dev_test_labs_client.py index 1cd3385cce5b..0ce6963ccf58 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/_dev_test_labs_client.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/_dev_test_labs_client.py @@ -8,11 +8,14 @@ from copy import deepcopy from typing import Any, Awaitable, TYPE_CHECKING +from typing_extensions import Self +from azure.core.pipeline import policies from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.mgmt.core import AsyncARMPipelineClient +from azure.mgmt.core.policies import AsyncARMAutoResourceProviderRegistrationPolicy -from .. import models +from .. import models as _models from .._serialization import Deserializer, Serializer from ._configuration import DevTestLabsClientConfiguration from .operations import ( @@ -126,9 +129,27 @@ def __init__( **kwargs: Any ) -> None: self._config = DevTestLabsClientConfiguration(credential=credential, subscription_id=subscription_id, **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)} + _policies = kwargs.pop("policies", None) + if _policies is None: + _policies = [ + policies.RequestIdPolicy(**kwargs), + self._config.headers_policy, + self._config.user_agent_policy, + self._config.proxy_policy, + policies.ContentDecodePolicy(**kwargs), + AsyncARMAutoResourceProviderRegistrationPolicy(), + self._config.redirect_policy, + self._config.retry_policy, + self._config.authentication_policy, + self._config.custom_hook_policy, + self._config.logging_policy, + policies.DistributedTracingPolicy(**kwargs), + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, + self._config.http_logging_policy, + ] + self._client: AsyncARMPipelineClient = AsyncARMPipelineClient(base_url=base_url, policies=_policies, **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 @@ -174,7 +195,9 @@ def __init__( self._client, self._config, self._serialize, self._deserialize ) - def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: + def _send_request( + self, request: HttpRequest, *, stream: bool = False, **kwargs: Any + ) -> Awaitable[AsyncHttpResponse]: """Runs the network request through the client's chained policies. >>> from azure.core.rest import HttpRequest @@ -194,14 +217,14 @@ def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncH request_copy = deepcopy(request) request_copy.url = self._client.format_url(request_copy.url) - return self._client.send_request(request_copy, **kwargs) + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore async def close(self) -> None: await self._client.close() - async def __aenter__(self) -> "DevTestLabsClient": + async def __aenter__(self) -> Self: await self._client.__aenter__() return self - async def __aexit__(self, *exc_details) -> None: + async def __aexit__(self, *exc_details: Any) -> None: await self._client.__aexit__(*exc_details) diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/__init__.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/__init__.py index 7ccc7d9fe973..152be74a3dfb 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/__init__.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/__init__.py @@ -33,7 +33,7 @@ from ._virtual_networks_operations import VirtualNetworksOperations from ._patch import __all__ as _patch_all -from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import +from ._patch import * # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk __all__ = [ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_arm_templates_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_arm_templates_operations.py index ed06baf5f455..9f01e516c455 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_arm_templates_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_arm_templates_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, Optional, Type, TypeVar import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -20,21 +20,19 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._arm_templates_operations import build_get_request, build_list_request -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -90,7 +88,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ArmTemplate or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.ArmTemplate] :raises ~azure.core.exceptions.HttpResponseError: @@ -98,12 +95,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArmTemplateList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArmTemplateList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -114,7 +109,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -124,12 +119,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -141,26 +134,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ArmTemplateList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -172,8 +165,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates"} # type: ignore - @distributed_trace_async async def get( self, @@ -197,12 +188,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=displayName)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArmTemplate or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArmTemplate :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -213,12 +203,10 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArmTemplate] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArmTemplate] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -226,15 +214,14 @@ async def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -243,11 +230,9 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ArmTemplate", pipeline_response) + deserialized = self._deserialize("ArmTemplate", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_artifact_sources_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_artifact_sources_operations.py index 808c638394d5..b4db242cb9cc 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_artifact_sources_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_artifact_sources_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, Type, TypeVar, Union, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -20,15 +21,13 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._artifact_sources_operations import ( build_create_or_update_request, build_delete_request, @@ -37,10 +36,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -93,7 +92,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ArtifactSource or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.ArtifactSource] :raises ~azure.core.exceptions.HttpResponseError: @@ -101,12 +99,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactSourceList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArtifactSourceList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -117,7 +113,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -126,12 +122,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -143,26 +137,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ArtifactSourceList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -174,8 +168,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -191,12 +183,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=displayName)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -207,27 +198,24 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactSource] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArtifactSource] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -236,14 +224,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ArtifactSource", pipeline_response) + deserialized = self._deserialize("ArtifactSource", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}"} # type: ignore + return deserialized # type: ignore @overload async def create_or_update( @@ -269,7 +255,6 @@ async def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: @@ -281,7 +266,7 @@ async def create_or_update( resource_group_name: str, lab_name: str, name: str, - artifact_source: IO, + artifact_source: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -295,11 +280,10 @@ async def create_or_update( :param name: The name of the artifact source. Required. :type name: str :param artifact_source: Properties of an artifact source. Required. - :type artifact_source: IO + :type artifact_source: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: @@ -311,7 +295,7 @@ async def create_or_update( resource_group_name: str, lab_name: str, name: str, - artifact_source: Union[_models.ArtifactSource, IO], + artifact_source: Union[_models.ArtifactSource, IO[bytes]], **kwargs: Any ) -> _models.ArtifactSource: """Create or replace an existing artifact source. @@ -322,18 +306,14 @@ async def create_or_update( :type lab_name: str :param name: The name of the artifact source. Required. :type name: str - :param artifact_source: Properties of an artifact source. Is either a model type or a IO type. - Required. - :type artifact_source: ~azure.mgmt.devtestlabs.models.ArtifactSource or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param artifact_source: Properties of an artifact source. Is either a ArtifactSource type or a + IO[bytes] type. Required. + :type artifact_source: ~azure.mgmt.devtestlabs.models.ArtifactSource or IO[bytes] :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -344,21 +324,19 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactSource] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.ArtifactSource] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(artifact_source, (IO, bytes)): + if isinstance(artifact_source, (IOBase, bytes)): _content = artifact_source else: _json = self._serialize.body(artifact_source, "ArtifactSource") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -367,15 +345,14 @@ async def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -384,18 +361,12 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("ArtifactSource", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("ArtifactSource", pipeline_response) + deserialized = self._deserialize("ArtifactSource", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -409,12 +380,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the artifact source. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -425,26 +395,23 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -454,9 +421,7 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace_async async def update( @@ -472,12 +437,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -488,16 +452,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactSource] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.ArtifactSource] = kwargs.pop("cls", None) _artifact_source = _models.ArtifactSourceFragment(tags=tags) _json = self._serialize.body(_artifact_source, "ArtifactSourceFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -505,15 +467,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -522,11 +483,9 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ArtifactSource", pipeline_response) + deserialized = self._deserialize("ArtifactSource", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_artifacts_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_artifacts_operations.py index c47fa1be7e67..4d038a93bb64 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_artifacts_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_artifacts_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, Type, TypeVar, Union, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -20,25 +21,23 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._artifacts_operations import ( build_generate_arm_template_request, build_get_request, build_list_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -94,7 +93,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Artifact or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Artifact] :raises ~azure.core.exceptions.HttpResponseError: @@ -102,12 +100,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArtifactList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -118,7 +114,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -128,12 +124,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -145,26 +139,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ArtifactList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -176,8 +170,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts"} # type: ignore - @distributed_trace_async async def get( self, @@ -201,12 +193,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=title)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Artifact or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Artifact :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -217,12 +208,10 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Artifact] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Artifact] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -230,15 +219,14 @@ async def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -247,14 +235,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Artifact", pipeline_response) + deserialized = self._deserialize("Artifact", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}"} # type: ignore + return deserialized # type: ignore @overload async def generate_arm_template( @@ -285,7 +271,6 @@ async def generate_arm_template( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArmTemplateInfo or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArmTemplateInfo :raises ~azure.core.exceptions.HttpResponseError: @@ -298,7 +283,7 @@ async def generate_arm_template( lab_name: str, artifact_source_name: str, name: str, - generate_arm_template_request: IO, + generate_arm_template_request: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -316,11 +301,10 @@ async def generate_arm_template( :type name: str :param generate_arm_template_request: Parameters for generating an ARM template for deploying artifacts. Required. - :type generate_arm_template_request: IO + :type generate_arm_template_request: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArmTemplateInfo or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArmTemplateInfo :raises ~azure.core.exceptions.HttpResponseError: @@ -333,7 +317,7 @@ async def generate_arm_template( lab_name: str, artifact_source_name: str, name: str, - generate_arm_template_request: Union[_models.GenerateArmTemplateRequest, IO], + generate_arm_template_request: Union[_models.GenerateArmTemplateRequest, IO[bytes]], **kwargs: Any ) -> _models.ArmTemplateInfo: """Generates an ARM template for the given artifact, uploads the required files to a storage @@ -348,18 +332,14 @@ async def generate_arm_template( :param name: The name of the artifact. Required. :type name: str :param generate_arm_template_request: Parameters for generating an ARM template for deploying - artifacts. Is either a model type or a IO type. Required. + artifacts. Is either a GenerateArmTemplateRequest type or a IO[bytes] type. Required. :type generate_arm_template_request: ~azure.mgmt.devtestlabs.models.GenerateArmTemplateRequest - or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + or IO[bytes] :return: ArmTemplateInfo or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArmTemplateInfo :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -370,21 +350,19 @@ async def generate_arm_template( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArmTemplateInfo] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.ArmTemplateInfo] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(generate_arm_template_request, (IO, bytes)): + if isinstance(generate_arm_template_request, (IOBase, bytes)): _content = generate_arm_template_request else: _json = self._serialize.body(generate_arm_template_request, "GenerateArmTemplateRequest") - request = build_generate_arm_template_request( + _request = build_generate_arm_template_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -394,15 +372,14 @@ async def generate_arm_template( content_type=content_type, json=_json, content=_content, - template_url=self.generate_arm_template.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -411,11 +388,9 @@ async def generate_arm_template( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ArmTemplateInfo", pipeline_response) + deserialized = self._deserialize("ArmTemplateInfo", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - generate_arm_template.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}/generateArmTemplate"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_costs_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_costs_operations.py index 7c5ef813cd2e..2d22a1553bbe 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_costs_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_costs_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Optional, Type, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -18,20 +19,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._costs_operations import build_create_or_update_request, build_get_request -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -70,12 +69,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($expand=labCostDetails)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabCost or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabCost :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -86,27 +84,24 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabCost] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabCost] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -115,14 +110,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("LabCost", pipeline_response) + deserialized = self._deserialize("LabCost", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}"} # type: ignore + return deserialized # type: ignore @overload async def create_or_update( @@ -148,7 +141,6 @@ async def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabCost or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabCost :raises ~azure.core.exceptions.HttpResponseError: @@ -160,7 +152,7 @@ async def create_or_update( resource_group_name: str, lab_name: str, name: str, - lab_cost: IO, + lab_cost: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -174,11 +166,10 @@ async def create_or_update( :param name: The name of the cost. Required. :type name: str :param lab_cost: A cost item. Required. - :type lab_cost: IO + :type lab_cost: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabCost or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabCost :raises ~azure.core.exceptions.HttpResponseError: @@ -186,7 +177,12 @@ async def create_or_update( @distributed_trace_async async def create_or_update( - self, resource_group_name: str, lab_name: str, name: str, lab_cost: Union[_models.LabCost, IO], **kwargs: Any + self, + resource_group_name: str, + lab_name: str, + name: str, + lab_cost: Union[_models.LabCost, IO[bytes]], + **kwargs: Any ) -> _models.LabCost: """Create or replace an existing cost. @@ -196,17 +192,13 @@ async def create_or_update( :type lab_name: str :param name: The name of the cost. Required. :type name: str - :param lab_cost: A cost item. Is either a model type or a IO type. Required. - :type lab_cost: ~azure.mgmt.devtestlabs.models.LabCost or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param lab_cost: A cost item. Is either a LabCost type or a IO[bytes] type. Required. + :type lab_cost: ~azure.mgmt.devtestlabs.models.LabCost or IO[bytes] :return: LabCost or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabCost :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -217,21 +209,19 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabCost] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.LabCost] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(lab_cost, (IO, bytes)): + if isinstance(lab_cost, (IOBase, bytes)): _content = lab_cost else: _json = self._serialize.body(lab_cost, "LabCost") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -240,15 +230,14 @@ async def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -257,15 +246,9 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("LabCost", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("LabCost", pipeline_response) + deserialized = self._deserialize("LabCost", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_custom_images_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_custom_images_operations.py index b2ec21669c64..3d6c88819c6c 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_custom_images_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_custom_images_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._custom_images_operations import ( build_create_or_update_request, build_delete_request, @@ -39,10 +40,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -95,7 +96,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either CustomImage or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.CustomImage] :raises ~azure.core.exceptions.HttpResponseError: @@ -103,12 +103,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImageList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.CustomImageList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -119,7 +117,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -128,12 +126,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -145,26 +141,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("CustomImageList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -176,8 +172,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -193,12 +187,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=vm)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: CustomImage or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.CustomImage :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -209,27 +202,24 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImage] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.CustomImage] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -238,24 +228,22 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("CustomImage", pipeline_response) + deserialized = self._deserialize("CustomImage", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( self, resource_group_name: str, lab_name: str, name: str, - custom_image: Union[_models.CustomImage, IO], + custom_image: Union[_models.CustomImage, IO[bytes]], **kwargs: Any - ) -> _models.CustomImage: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -266,21 +254,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImage] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(custom_image, (IO, bytes)): + if isinstance(custom_image, (IOBase, bytes)): _content = custom_image else: _json = self._serialize.body(custom_image, "CustomImage") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -289,35 +275,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("CustomImage", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("CustomImage", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -343,14 +327,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either CustomImage or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.CustomImage] @@ -363,7 +339,7 @@ async def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - custom_image: IO, + custom_image: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -377,18 +353,10 @@ async def begin_create_or_update( :param name: The name of the custom image. Required. :type name: str :param custom_image: A custom image. Required. - :type custom_image: IO + :type custom_image: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either CustomImage or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.CustomImage] @@ -401,7 +369,7 @@ async def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - custom_image: Union[_models.CustomImage, IO], + custom_image: Union[_models.CustomImage, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.CustomImage]: """Create or replace an existing custom image. This operation can take a while to complete. @@ -412,19 +380,9 @@ async def begin_create_or_update( :type lab_name: str :param name: The name of the custom image. Required. :type name: str - :param custom_image: A custom image. Is either a model type or a IO type. Required. - :type custom_image: ~azure.mgmt.devtestlabs.models.CustomImage or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param custom_image: A custom image. Is either a CustomImage type or a IO[bytes] type. + Required. + :type custom_image: ~azure.mgmt.devtestlabs.models.CustomImage or IO[bytes] :return: An instance of AsyncLROPoller that returns either CustomImage or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.CustomImage] @@ -433,16 +391,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImage] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.CustomImage] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -454,35 +410,36 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("CustomImage", pipeline_response) + deserialized = self._deserialize("CustomImage", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.CustomImage].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return AsyncLROPoller[_models.CustomImage]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -493,38 +450,42 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -538,14 +499,6 @@ async def begin_delete( :type lab_name: str :param name: The name of the custom image. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -553,15 +506,13 @@ async def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -571,28 +522,27 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def update( @@ -608,12 +558,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: CustomImage or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.CustomImage :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -624,16 +573,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImage] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.CustomImage] = kwargs.pop("cls", None) _custom_image = _models.CustomImageFragment(tags=tags) _json = self._serialize.body(_custom_image, "CustomImageFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -641,15 +588,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -658,11 +604,9 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("CustomImage", pipeline_response) + deserialized = self._deserialize("CustomImage", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_disks_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_disks_operations.py index 1dc1ee6b322d..514a5cc135cf 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_disks_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_disks_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._disks_operations import ( build_attach_request, build_create_or_update_request, @@ -41,10 +42,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -100,7 +101,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Disk or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Disk] :raises ~azure.core.exceptions.HttpResponseError: @@ -108,12 +108,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DiskList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.DiskList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -124,7 +122,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -134,12 +132,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -151,26 +147,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("DiskList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -182,8 +178,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks"} # type: ignore - @distributed_trace_async async def get( self, @@ -207,12 +201,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=diskType)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Disk or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Disk :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -223,12 +216,10 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Disk] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Disk] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -236,15 +227,14 @@ async def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -253,14 +243,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Disk", pipeline_response) + deserialized = self._deserialize("Disk", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( self, @@ -268,10 +256,10 @@ async def _create_or_update_initial( lab_name: str, user_name: str, name: str, - disk: Union[_models.Disk, IO], + disk: Union[_models.Disk, IO[bytes]], **kwargs: Any - ) -> _models.Disk: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -282,21 +270,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Disk] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(disk, (IO, bytes)): + if isinstance(disk, (IOBase, bytes)): _content = disk else: _json = self._serialize.body(disk, "Disk") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -306,35 +292,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Disk", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Disk", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -363,14 +347,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Disk or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Disk] :raises ~azure.core.exceptions.HttpResponseError: @@ -383,7 +359,7 @@ async def begin_create_or_update( lab_name: str, user_name: str, name: str, - disk: IO, + disk: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -399,18 +375,10 @@ async def begin_create_or_update( :param name: The name of the disk. Required. :type name: str :param disk: A Disk. Required. - :type disk: IO + :type disk: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Disk or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Disk] :raises ~azure.core.exceptions.HttpResponseError: @@ -423,7 +391,7 @@ async def begin_create_or_update( lab_name: str, user_name: str, name: str, - disk: Union[_models.Disk, IO], + disk: Union[_models.Disk, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.Disk]: """Create or replace an existing disk. This operation can take a while to complete. @@ -436,19 +404,8 @@ async def begin_create_or_update( :type user_name: str :param name: The name of the disk. Required. :type name: str - :param disk: A Disk. Is either a model type or a IO type. Required. - :type disk: ~azure.mgmt.devtestlabs.models.Disk or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param disk: A Disk. Is either a Disk type or a IO[bytes] type. Required. + :type disk: ~azure.mgmt.devtestlabs.models.Disk or IO[bytes] :return: An instance of AsyncLROPoller that returns either Disk or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Disk] :raises ~azure.core.exceptions.HttpResponseError: @@ -456,16 +413,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Disk] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Disk] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -478,35 +433,36 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Disk", pipeline_response) + deserialized = self._deserialize("Disk", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.Disk].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return AsyncLROPoller[_models.Disk]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -517,39 +473,43 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -565,14 +525,6 @@ async def begin_delete( :type user_name: str :param name: The name of the disk. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -580,15 +532,13 @@ async def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -599,28 +549,27 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def update( @@ -644,12 +593,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Disk or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Disk :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -660,16 +608,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Disk] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Disk] = kwargs.pop("cls", None) _disk = _models.DiskFragment(tags=tags) _json = self._serialize.body(_disk, "DiskFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -678,15 +624,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -695,16 +640,14 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Disk", pipeline_response) + deserialized = self._deserialize("Disk", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return deserialized # type: ignore - async def _attach_initial( # pylint: disable=inconsistent-return-statements + async def _attach_initial( self, resource_group_name: str, lab_name: str, @@ -712,8 +655,8 @@ async def _attach_initial( # pylint: disable=inconsistent-return-statements name: str, leased_by_lab_vm_id: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -724,16 +667,14 @@ async def _attach_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) _attach_disk_properties = _models.AttachDiskProperties(leased_by_lab_vm_id=leased_by_lab_vm_id) _json = self._serialize.body(_attach_disk_properties, "AttachDiskProperties") - request = build_attach_request( + _request = build_attach_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -742,27 +683,33 @@ async def _attach_initial( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self._attach_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _attach_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/attach"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_attach( @@ -788,14 +735,6 @@ async def begin_attach( :param leased_by_lab_vm_id: The resource ID of the Lab virtual machine to which the disk is attached. Default value is None. :type leased_by_lab_vm_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -803,16 +742,14 @@ async def begin_attach( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._attach_initial( # type: ignore + raw_result = await self._attach_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -825,30 +762,29 @@ async def begin_attach( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_attach.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/attach"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - async def _detach_initial( # pylint: disable=inconsistent-return-statements + async def _detach_initial( self, resource_group_name: str, lab_name: str, @@ -856,8 +792,8 @@ async def _detach_initial( # pylint: disable=inconsistent-return-statements name: str, leased_by_lab_vm_id: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -868,16 +804,14 @@ async def _detach_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) _detach_disk_properties = _models.DetachDiskProperties(leased_by_lab_vm_id=leased_by_lab_vm_id) _json = self._serialize.body(_detach_disk_properties, "DetachDiskProperties") - request = build_detach_request( + _request = build_detach_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -886,27 +820,33 @@ async def _detach_initial( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self._detach_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _detach_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/detach"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_detach( @@ -932,14 +872,6 @@ async def begin_detach( :param leased_by_lab_vm_id: The resource ID of the Lab VM to which the disk is attached. Default value is None. :type leased_by_lab_vm_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -947,16 +879,14 @@ async def begin_detach( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._detach_initial( # type: ignore + raw_result = await self._detach_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -969,25 +899,24 @@ async def begin_detach( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_detach.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/detach"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_environments_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_environments_operations.py index 5696716c1159..9fda21762060 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_environments_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_environments_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._environments_operations import ( build_create_or_update_request, build_delete_request, @@ -39,10 +40,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -98,7 +99,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either DtlEnvironment or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.DtlEnvironment] :raises ~azure.core.exceptions.HttpResponseError: @@ -106,12 +106,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironmentList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.DtlEnvironmentList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -122,7 +120,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -132,12 +130,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -149,26 +145,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("DtlEnvironmentList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -180,8 +176,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments"} # type: ignore - @distributed_trace_async async def get( self, @@ -205,12 +199,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=deploymentProperties)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: DtlEnvironment or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.DtlEnvironment :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -221,12 +214,10 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironment] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.DtlEnvironment] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -234,15 +225,14 @@ async def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -251,14 +241,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("DtlEnvironment", pipeline_response) + deserialized = self._deserialize("DtlEnvironment", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( self, @@ -266,10 +254,10 @@ async def _create_or_update_initial( lab_name: str, user_name: str, name: str, - dtl_environment: Union[_models.DtlEnvironment, IO], + dtl_environment: Union[_models.DtlEnvironment, IO[bytes]], **kwargs: Any - ) -> _models.DtlEnvironment: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -280,21 +268,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironment] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(dtl_environment, (IO, bytes)): + if isinstance(dtl_environment, (IOBase, bytes)): _content = dtl_environment else: _json = self._serialize.body(dtl_environment, "DtlEnvironment") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -304,35 +290,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("DtlEnvironment", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("DtlEnvironment", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -362,14 +346,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either DtlEnvironment or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.DtlEnvironment] @@ -383,7 +359,7 @@ async def begin_create_or_update( lab_name: str, user_name: str, name: str, - dtl_environment: IO, + dtl_environment: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -400,18 +376,10 @@ async def begin_create_or_update( :type name: str :param dtl_environment: An environment, which is essentially an ARM template deployment. Required. - :type dtl_environment: IO + :type dtl_environment: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either DtlEnvironment or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.DtlEnvironment] @@ -425,7 +393,7 @@ async def begin_create_or_update( lab_name: str, user_name: str, name: str, - dtl_environment: Union[_models.DtlEnvironment, IO], + dtl_environment: Union[_models.DtlEnvironment, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.DtlEnvironment]: """Create or replace an existing environment. This operation can take a while to complete. @@ -439,19 +407,8 @@ async def begin_create_or_update( :param name: The name of the environment. Required. :type name: str :param dtl_environment: An environment, which is essentially an ARM template deployment. Is - either a model type or a IO type. Required. - :type dtl_environment: ~azure.mgmt.devtestlabs.models.DtlEnvironment or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + either a DtlEnvironment type or a IO[bytes] type. Required. + :type dtl_environment: ~azure.mgmt.devtestlabs.models.DtlEnvironment or IO[bytes] :return: An instance of AsyncLROPoller that returns either DtlEnvironment or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.DtlEnvironment] @@ -460,16 +417,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironment] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.DtlEnvironment] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -482,35 +437,36 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("DtlEnvironment", pipeline_response) + deserialized = self._deserialize("DtlEnvironment", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.DtlEnvironment].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return AsyncLROPoller[_models.DtlEnvironment]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -521,39 +477,43 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -569,14 +529,6 @@ async def begin_delete( :type user_name: str :param name: The name of the environment. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -584,15 +536,13 @@ async def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -603,28 +553,27 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def update( @@ -648,12 +597,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: DtlEnvironment or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.DtlEnvironment :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -664,16 +612,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironment] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.DtlEnvironment] = kwargs.pop("cls", None) _dtl_environment = _models.DtlEnvironmentFragment(tags=tags) _json = self._serialize.body(_dtl_environment, "DtlEnvironmentFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -682,15 +628,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -699,11 +644,9 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("DtlEnvironment", pipeline_response) + deserialized = self._deserialize("DtlEnvironment", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_formulas_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_formulas_operations.py index 46c29c369fe0..307c1a5640bb 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_formulas_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_formulas_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._formulas_operations import ( build_create_or_update_request, build_delete_request, @@ -39,10 +40,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -95,7 +96,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Formula or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Formula] :raises ~azure.core.exceptions.HttpResponseError: @@ -103,12 +103,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.FormulaList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.FormulaList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -119,7 +117,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -128,12 +126,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -145,26 +141,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("FormulaList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -176,8 +172,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -193,12 +187,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=description)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Formula or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Formula :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -209,27 +202,24 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Formula] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Formula] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -238,19 +228,22 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Formula", pipeline_response) + deserialized = self._deserialize("Formula", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( - self, resource_group_name: str, lab_name: str, name: str, formula: Union[_models.Formula, IO], **kwargs: Any - ) -> _models.Formula: - error_map = { + self, + resource_group_name: str, + lab_name: str, + name: str, + formula: Union[_models.Formula, IO[bytes]], + **kwargs: Any + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -261,21 +254,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Formula] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(formula, (IO, bytes)): + if isinstance(formula, (IOBase, bytes)): _content = formula else: _json = self._serialize.body(formula, "Formula") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -284,35 +275,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Formula", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Formula", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -339,14 +328,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Formula or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Formula] @@ -359,7 +340,7 @@ async def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - formula: IO, + formula: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -374,18 +355,10 @@ async def begin_create_or_update( :type name: str :param formula: A formula for creating a VM, specifying an image base and other parameters. Required. - :type formula: IO + :type formula: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Formula or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Formula] @@ -394,7 +367,12 @@ async def begin_create_or_update( @distributed_trace_async async def begin_create_or_update( - self, resource_group_name: str, lab_name: str, name: str, formula: Union[_models.Formula, IO], **kwargs: Any + self, + resource_group_name: str, + lab_name: str, + name: str, + formula: Union[_models.Formula, IO[bytes]], + **kwargs: Any ) -> AsyncLROPoller[_models.Formula]: """Create or replace an existing formula. This operation can take a while to complete. @@ -405,19 +383,8 @@ async def begin_create_or_update( :param name: The name of the formula. Required. :type name: str :param formula: A formula for creating a VM, specifying an image base and other parameters. Is - either a model type or a IO type. Required. - :type formula: ~azure.mgmt.devtestlabs.models.Formula or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + either a Formula type or a IO[bytes] type. Required. + :type formula: ~azure.mgmt.devtestlabs.models.Formula or IO[bytes] :return: An instance of AsyncLROPoller that returns either Formula or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Formula] @@ -426,16 +393,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Formula] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Formula] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -447,30 +412,31 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Formula", pipeline_response) + deserialized = self._deserialize("Formula", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.Formula].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return AsyncLROPoller[_models.Formula]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -484,12 +450,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the formula. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -500,26 +465,23 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -529,9 +491,7 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace_async async def update( @@ -547,12 +507,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Formula or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Formula :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -563,16 +522,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Formula] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Formula] = kwargs.pop("cls", None) _formula = _models.FormulaFragment(tags=tags) _json = self._serialize.body(_formula, "FormulaFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -580,15 +537,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -597,11 +553,9 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Formula", pipeline_response) + deserialized = self._deserialize("Formula", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_gallery_images_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_gallery_images_operations.py index 6d766486dacc..1148df9d2c75 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_gallery_images_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_gallery_images_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, Optional, Type, TypeVar import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -20,20 +20,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._gallery_images_operations import build_list_request -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -86,7 +84,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either GalleryImage or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.GalleryImage] :raises ~azure.core.exceptions.HttpResponseError: @@ -94,12 +91,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.GalleryImageList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.GalleryImageList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -110,7 +105,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -119,12 +114,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -136,26 +129,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("GalleryImageList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -166,5 +159,3 @@ async def get_next(next_link=None): return pipeline_response return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/galleryimages"} # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_global_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_global_schedules_operations.py index 301884641c2f..4db957b91582 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_global_schedules_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_global_schedules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._global_schedules_operations import ( build_create_or_update_request, build_delete_request, @@ -42,10 +43,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -92,7 +93,6 @@ def list_by_subscription( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -100,12 +100,10 @@ def list_by_subscription( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -116,19 +114,17 @@ def list_by_subscription( def prepare_request(next_link=None): if not next_link: - request = build_list_by_subscription_request( + _request = build_list_by_subscription_request( subscription_id=self._config.subscription_id, expand=expand, filter=filter, top=top, orderby=orderby, api_version=api_version, - template_url=self.list_by_subscription.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -140,26 +136,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -171,8 +167,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_subscription.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.DevTestLab/schedules"} # type: ignore - @distributed_trace def list_by_resource_group( self, @@ -199,7 +193,6 @@ def list_by_resource_group( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -207,12 +200,10 @@ def list_by_resource_group( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -223,7 +214,7 @@ def list_by_resource_group( def prepare_request(next_link=None): if not next_link: - request = build_list_by_resource_group_request( + _request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, expand=expand, @@ -231,12 +222,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -248,26 +237,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -279,8 +268,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -294,12 +281,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=status)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -310,26 +296,23 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -338,14 +321,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}"} # type: ignore + return deserialized # type: ignore @overload async def create_or_update( @@ -368,7 +349,6 @@ async def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -379,7 +359,7 @@ async def create_or_update( self, resource_group_name: str, name: str, - schedule: IO, + schedule: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -391,11 +371,10 @@ async def create_or_update( :param name: The name of the schedule. Required. :type name: str :param schedule: A schedule. Required. - :type schedule: IO + :type schedule: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -403,7 +382,7 @@ async def create_or_update( @distributed_trace_async async def create_or_update( - self, resource_group_name: str, name: str, schedule: Union[_models.Schedule, IO], **kwargs: Any + self, resource_group_name: str, name: str, schedule: Union[_models.Schedule, IO[bytes]], **kwargs: Any ) -> _models.Schedule: """Create or replace an existing schedule. @@ -411,17 +390,13 @@ async def create_or_update( :type resource_group_name: str :param name: The name of the schedule. Required. :type name: str - :param schedule: A schedule. Is either a model type or a IO type. Required. - :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param schedule: A schedule. Is either a Schedule type or a IO[bytes] type. Required. + :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO[bytes] :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -432,21 +407,19 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(schedule, (IO, bytes)): + if isinstance(schedule, (IOBase, bytes)): _content = schedule else: _json = self._serialize.body(schedule, "Schedule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, @@ -454,15 +427,14 @@ async def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -471,18 +443,12 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Schedule", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -494,12 +460,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type resource_group_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -510,25 +475,22 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -538,9 +500,7 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace_async async def update( @@ -554,12 +514,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -570,31 +529,28 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) _schedule = _models.ScheduleFragment(tags=tags) _json = self._serialize.body(_schedule, "ScheduleFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -603,19 +559,15 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized + return deserialized # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}"} # type: ignore - - async def _execute_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + async def _execute_initial(self, resource_group_name: str, name: str, **kwargs: Any) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -626,37 +578,41 @@ async def _execute_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_execute_request( + _request = build_execute_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._execute_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _execute_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/execute"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_execute(self, resource_group_name: str, name: str, **kwargs: Any) -> AsyncLROPoller[None]: @@ -666,14 +622,6 @@ async def begin_execute(self, resource_group_name: str, name: str, **kwargs: Any :type resource_group_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -681,15 +629,13 @@ async def begin_execute(self, resource_group_name: str, name: str, **kwargs: Any _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._execute_initial( # type: ignore + raw_result = await self._execute_initial( resource_group_name=resource_group_name, name=name, api_version=api_version, @@ -698,38 +644,37 @@ async def begin_execute(self, resource_group_name: str, name: str, **kwargs: Any params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_execute.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/execute"} # type: ignore - - async def _retarget_initial( # pylint: disable=inconsistent-return-statements + async def _retarget_initial( self, resource_group_name: str, name: str, current_resource_id: Optional[str] = None, target_resource_id: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -740,45 +685,49 @@ async def _retarget_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) _retarget_schedule_properties = _models.RetargetScheduleProperties( current_resource_id=current_resource_id, target_resource_id=target_resource_id ) _json = self._serialize.body(_retarget_schedule_properties, "RetargetScheduleProperties") - request = build_retarget_request( + _request = build_retarget_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._retarget_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _retarget_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/retarget"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_retarget( @@ -801,14 +750,6 @@ async def begin_retarget( :param target_resource_id: The resource Id of the virtual machine that the schedule should be retargeted to. Default value is None. :type target_resource_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -816,16 +757,14 @@ async def begin_retarget( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._retarget_initial( # type: ignore + raw_result = await self._retarget_initial( resource_group_name=resource_group_name, name=name, current_resource_id=current_resource_id, @@ -837,25 +776,24 @@ async def begin_retarget( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_retarget.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/retarget"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_labs_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_labs_operations.py index 17fc4776e464..765558cff8f7 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_labs_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_labs_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,8 +7,9 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import datetime +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -18,12 +19,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -31,7 +33,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._labs_operations import ( build_claim_any_vm_request, build_create_environment_request, @@ -47,10 +48,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -97,7 +98,6 @@ def list_by_subscription( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Lab or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -105,12 +105,10 @@ def list_by_subscription( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -121,19 +119,17 @@ def list_by_subscription( def prepare_request(next_link=None): if not next_link: - request = build_list_by_subscription_request( + _request = build_list_by_subscription_request( subscription_id=self._config.subscription_id, expand=expand, filter=filter, top=top, orderby=orderby, api_version=api_version, - template_url=self.list_by_subscription.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -145,26 +141,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("LabList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -176,8 +172,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_subscription.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.DevTestLab/labs"} # type: ignore - @distributed_trace def list_by_resource_group( self, @@ -204,7 +198,6 @@ def list_by_resource_group( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Lab or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -212,12 +205,10 @@ def list_by_resource_group( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -228,7 +219,7 @@ def list_by_resource_group( def prepare_request(next_link=None): if not next_link: - request = build_list_by_resource_group_request( + _request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, expand=expand, @@ -236,12 +227,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -253,26 +242,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("LabList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -284,8 +273,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -299,12 +286,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=defaultStorageAccount)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Lab or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Lab :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -315,26 +301,23 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Lab] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Lab] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -343,19 +326,17 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Lab", pipeline_response) + deserialized = self._deserialize("Lab", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( - self, resource_group_name: str, name: str, lab: Union[_models.Lab, IO], **kwargs: Any - ) -> _models.Lab: - error_map = { + self, resource_group_name: str, name: str, lab: Union[_models.Lab, IO[bytes]], **kwargs: Any + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -366,21 +347,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Lab] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(lab, (IO, bytes)): + if isinstance(lab, (IOBase, bytes)): _content = lab else: _json = self._serialize.body(lab, "Lab") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, @@ -388,35 +367,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Lab", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Lab", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -439,14 +416,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Lab or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -454,7 +423,13 @@ async def begin_create_or_update( @overload async def begin_create_or_update( - self, resource_group_name: str, name: str, lab: IO, *, content_type: str = "application/json", **kwargs: Any + self, + resource_group_name: str, + name: str, + lab: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any ) -> AsyncLROPoller[_models.Lab]: """Create or replace an existing lab. This operation can take a while to complete. @@ -463,18 +438,10 @@ async def begin_create_or_update( :param name: The name of the lab. Required. :type name: str :param lab: A lab. Required. - :type lab: IO + :type lab: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Lab or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -482,7 +449,7 @@ async def begin_create_or_update( @distributed_trace_async async def begin_create_or_update( - self, resource_group_name: str, name: str, lab: Union[_models.Lab, IO], **kwargs: Any + self, resource_group_name: str, name: str, lab: Union[_models.Lab, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.Lab]: """Create or replace an existing lab. This operation can take a while to complete. @@ -490,19 +457,8 @@ async def begin_create_or_update( :type resource_group_name: str :param name: The name of the lab. Required. :type name: str - :param lab: A lab. Is either a model type or a IO type. Required. - :type lab: ~azure.mgmt.devtestlabs.models.Lab or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param lab: A lab. Is either a Lab type or a IO[bytes] type. Required. + :type lab: ~azure.mgmt.devtestlabs.models.Lab or IO[bytes] :return: An instance of AsyncLROPoller that returns either Lab or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -510,16 +466,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Lab] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Lab] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, name=name, lab=lab, @@ -530,35 +484,34 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Lab", pipeline_response) + deserialized = self._deserialize("Lab", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.Lab].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return AsyncLROPoller[_models.Lab]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + async def _delete_initial(self, resource_group_name: str, name: str, **kwargs: Any) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -569,37 +522,41 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_delete(self, resource_group_name: str, name: str, **kwargs: Any) -> AsyncLROPoller[None]: @@ -609,14 +566,6 @@ async def begin_delete(self, resource_group_name: str, name: str, **kwargs: Any) :type resource_group_name: str :param name: The name of the lab. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -624,15 +573,13 @@ async def begin_delete(self, resource_group_name: str, name: str, **kwargs: Any) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, name=name, api_version=api_version, @@ -641,28 +588,27 @@ async def begin_delete(self, resource_group_name: str, name: str, **kwargs: Any) params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def update( @@ -676,12 +622,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Lab or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Lab :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -692,31 +637,28 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Lab] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Lab] = kwargs.pop("cls", None) _lab = _models.LabFragment(tags=tags) _json = self._serialize.body(_lab, "LabFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -725,19 +667,15 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Lab", pipeline_response) + deserialized = self._deserialize("Lab", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized + return deserialized # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore - - async def _claim_any_vm_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + async def _claim_any_vm_initial(self, resource_group_name: str, name: str, **kwargs: Any) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -748,37 +686,41 @@ async def _claim_any_vm_initial( # pylint: disable=inconsistent-return-statemen _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_claim_any_vm_request( + _request = build_claim_any_vm_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._claim_any_vm_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _claim_any_vm_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/claimAnyVm"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_claim_any_vm(self, resource_group_name: str, name: str, **kwargs: Any) -> AsyncLROPoller[None]: @@ -789,14 +731,6 @@ async def begin_claim_any_vm(self, resource_group_name: str, name: str, **kwargs :type resource_group_name: str :param name: The name of the lab. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -804,15 +738,13 @@ async def begin_claim_any_vm(self, resource_group_name: str, name: str, **kwargs _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._claim_any_vm_initial( # type: ignore + raw_result = await self._claim_any_vm_initial( resource_group_name=resource_group_name, name=name, api_version=api_version, @@ -821,37 +753,36 @@ async def begin_claim_any_vm(self, resource_group_name: str, name: str, **kwargs params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_claim_any_vm.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/claimAnyVm"} # type: ignore - - async def _create_environment_initial( # pylint: disable=inconsistent-return-statements + async def _create_environment_initial( self, resource_group_name: str, name: str, - lab_virtual_machine_creation_parameter: Union[_models.LabVirtualMachineCreationParameter, IO], + lab_virtual_machine_creation_parameter: Union[_models.LabVirtualMachineCreationParameter, IO[bytes]], **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -862,21 +793,19 @@ async def _create_environment_initial( # pylint: disable=inconsistent-return-st _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(lab_virtual_machine_creation_parameter, (IO, bytes)): + if isinstance(lab_virtual_machine_creation_parameter, (IOBase, bytes)): _content = lab_virtual_machine_creation_parameter else: _json = self._serialize.body(lab_virtual_machine_creation_parameter, "LabVirtualMachineCreationParameter") - request = build_create_environment_request( + _request = build_create_environment_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, @@ -884,27 +813,33 @@ async def _create_environment_initial( # pylint: disable=inconsistent-return-st content_type=content_type, json=_json, content=_content, - template_url=self._create_environment_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_environment_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/createEnvironment"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_environment( @@ -929,14 +864,6 @@ async def begin_create_environment( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -947,7 +874,7 @@ async def begin_create_environment( self, resource_group_name: str, name: str, - lab_virtual_machine_creation_parameter: IO, + lab_virtual_machine_creation_parameter: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -960,18 +887,10 @@ async def begin_create_environment( :type name: str :param lab_virtual_machine_creation_parameter: Properties for creating a virtual machine. Required. - :type lab_virtual_machine_creation_parameter: IO + :type lab_virtual_machine_creation_parameter: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -982,7 +901,7 @@ async def begin_create_environment( self, resource_group_name: str, name: str, - lab_virtual_machine_creation_parameter: Union[_models.LabVirtualMachineCreationParameter, IO], + lab_virtual_machine_creation_parameter: Union[_models.LabVirtualMachineCreationParameter, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[None]: """Create virtual machines in a lab. This operation can take a while to complete. @@ -992,20 +911,9 @@ async def begin_create_environment( :param name: The name of the lab. Required. :type name: str :param lab_virtual_machine_creation_parameter: Properties for creating a virtual machine. Is - either a model type or a IO type. Required. + either a LabVirtualMachineCreationParameter type or a IO[bytes] type. Required. :type lab_virtual_machine_creation_parameter: - ~azure.mgmt.devtestlabs.models.LabVirtualMachineCreationParameter or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + ~azure.mgmt.devtestlabs.models.LabVirtualMachineCreationParameter or IO[bytes] :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1013,16 +921,14 @@ async def begin_create_environment( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_environment_initial( # type: ignore + raw_result = await self._create_environment_initial( resource_group_name=resource_group_name, name=name, lab_virtual_machine_creation_parameter=lab_virtual_machine_creation_parameter, @@ -1033,38 +939,37 @@ async def begin_create_environment( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_create_environment.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/createEnvironment"} # type: ignore - - async def _export_resource_usage_initial( # pylint: disable=inconsistent-return-statements + async def _export_resource_usage_initial( self, resource_group_name: str, name: str, blob_storage_absolute_sas_uri: Optional[str] = None, usage_start_date: Optional[datetime.datetime] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1075,45 +980,49 @@ async def _export_resource_usage_initial( # pylint: disable=inconsistent-return _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) _export_resource_usage_parameters = _models.ExportResourceUsageParameters( blob_storage_absolute_sas_uri=blob_storage_absolute_sas_uri, usage_start_date=usage_start_date ) _json = self._serialize.body(_export_resource_usage_parameters, "ExportResourceUsageParameters") - request = build_export_resource_usage_request( + _request = build_export_resource_usage_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._export_resource_usage_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _export_resource_usage_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/exportResourceUsage"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_export_resource_usage( @@ -1137,14 +1046,6 @@ async def begin_export_resource_usage( :param usage_start_date: The start time of the usage. If not provided, usage will be reported since the beginning of data collection. Default value is None. :type usage_start_date: ~datetime.datetime - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1152,16 +1053,14 @@ async def begin_export_resource_usage( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._export_resource_usage_initial( # type: ignore + raw_result = await self._export_resource_usage_initial( resource_group_name=resource_group_name, name=name, blob_storage_absolute_sas_uri=blob_storage_absolute_sas_uri, @@ -1173,28 +1072,27 @@ async def begin_export_resource_usage( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_export_resource_usage.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/exportResourceUsage"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def generate_upload_uri( @@ -1208,12 +1106,11 @@ async def generate_upload_uri( :type name: str :param blob_name: The blob name of the upload URI. Default value is None. :type blob_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: GenerateUploadUriResponse or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.GenerateUploadUriResponse :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1224,31 +1121,28 @@ async def generate_upload_uri( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.GenerateUploadUriResponse] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.GenerateUploadUriResponse] = kwargs.pop("cls", None) _generate_upload_uri_parameter = _models.GenerateUploadUriParameter(blob_name=blob_name) _json = self._serialize.body(_generate_upload_uri_parameter, "GenerateUploadUriParameter") - request = build_generate_upload_uri_request( + _request = build_generate_upload_uri_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.generate_upload_uri.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1257,24 +1151,22 @@ async def generate_upload_uri( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("GenerateUploadUriResponse", pipeline_response) + deserialized = self._deserialize("GenerateUploadUriResponse", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - generate_upload_uri.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/generateUploadUri"} # type: ignore + return deserialized # type: ignore - async def _import_virtual_machine_initial( # pylint: disable=inconsistent-return-statements + async def _import_virtual_machine_initial( self, resource_group_name: str, name: str, source_virtual_machine_resource_id: Optional[str] = None, destination_virtual_machine_name: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1285,11 +1177,9 @@ async def _import_virtual_machine_initial( # pylint: disable=inconsistent-retur _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) _import_lab_virtual_machine_request = _models.ImportLabVirtualMachineRequest( destination_virtual_machine_name=destination_virtual_machine_name, @@ -1297,34 +1187,40 @@ async def _import_virtual_machine_initial( # pylint: disable=inconsistent-retur ) _json = self._serialize.body(_import_lab_virtual_machine_request, "ImportLabVirtualMachineRequest") - request = build_import_virtual_machine_request( + _request = build_import_virtual_machine_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._import_virtual_machine_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _import_virtual_machine_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/importVirtualMachine"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_import_virtual_machine( @@ -1347,14 +1243,6 @@ async def begin_import_virtual_machine( :param destination_virtual_machine_name: The name of the virtual machine in the destination lab. Default value is None. :type destination_virtual_machine_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1362,16 +1250,14 @@ async def begin_import_virtual_machine( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._import_virtual_machine_initial( # type: ignore + raw_result = await self._import_virtual_machine_initial( resource_group_name=resource_group_name, name=name, source_virtual_machine_resource_id=source_virtual_machine_resource_id, @@ -1383,28 +1269,27 @@ async def begin_import_virtual_machine( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_import_virtual_machine.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/importVirtualMachine"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def list_vhds(self, resource_group_name: str, name: str, **kwargs: Any) -> AsyncIterable["_models.LabVhd"]: @@ -1414,7 +1299,6 @@ def list_vhds(self, resource_group_name: str, name: str, **kwargs: Any) -> Async :type resource_group_name: str :param name: The name of the lab. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either LabVhd or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.LabVhd] :raises ~azure.core.exceptions.HttpResponseError: @@ -1422,12 +1306,10 @@ def list_vhds(self, resource_group_name: str, name: str, **kwargs: Any) -> Async _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVhdList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabVhdList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1438,17 +1320,15 @@ def list_vhds(self, resource_group_name: str, name: str, **kwargs: Any) -> Async def prepare_request(next_link=None): if not next_link: - request = build_list_vhds_request( + _request = build_list_vhds_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_vhds.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -1460,26 +1340,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("LabVhdList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1490,5 +1370,3 @@ async def get_next(next_link=None): return pipeline_response return AsyncItemPaged(get_next, extract_data) - - list_vhds.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/listVhds"} # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_notification_channels_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_notification_channels_operations.py index 1325861c2b07..612fc1a8ea04 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_notification_channels_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_notification_channels_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, Type, TypeVar, Union, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -20,15 +21,13 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._notification_channels_operations import ( build_create_or_update_request, build_delete_request, @@ -38,10 +37,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -94,7 +93,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either NotificationChannel or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.NotificationChannel] @@ -103,12 +101,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.NotificationChannelList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.NotificationChannelList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -119,7 +115,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -128,12 +124,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -145,26 +139,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("NotificationChannelList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -176,8 +170,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -193,12 +185,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=webHookUrl)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -209,27 +200,24 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.NotificationChannel] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.NotificationChannel] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -238,14 +226,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("NotificationChannel", pipeline_response) + deserialized = self._deserialize("NotificationChannel", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}"} # type: ignore + return deserialized # type: ignore @overload async def create_or_update( @@ -271,7 +257,6 @@ async def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: @@ -283,7 +268,7 @@ async def create_or_update( resource_group_name: str, lab_name: str, name: str, - notification_channel: IO, + notification_channel: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -297,11 +282,10 @@ async def create_or_update( :param name: The name of the notification channel. Required. :type name: str :param notification_channel: A notification. Required. - :type notification_channel: IO + :type notification_channel: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: @@ -313,7 +297,7 @@ async def create_or_update( resource_group_name: str, lab_name: str, name: str, - notification_channel: Union[_models.NotificationChannel, IO], + notification_channel: Union[_models.NotificationChannel, IO[bytes]], **kwargs: Any ) -> _models.NotificationChannel: """Create or replace an existing notification channel. @@ -324,17 +308,14 @@ async def create_or_update( :type lab_name: str :param name: The name of the notification channel. Required. :type name: str - :param notification_channel: A notification. Is either a model type or a IO type. Required. - :type notification_channel: ~azure.mgmt.devtestlabs.models.NotificationChannel or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param notification_channel: A notification. Is either a NotificationChannel type or a + IO[bytes] type. Required. + :type notification_channel: ~azure.mgmt.devtestlabs.models.NotificationChannel or IO[bytes] :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -345,21 +326,19 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.NotificationChannel] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.NotificationChannel] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(notification_channel, (IO, bytes)): + if isinstance(notification_channel, (IOBase, bytes)): _content = notification_channel else: _json = self._serialize.body(notification_channel, "NotificationChannel") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -368,15 +347,14 @@ async def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -385,18 +363,12 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("NotificationChannel", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("NotificationChannel", pipeline_response) + deserialized = self._deserialize("NotificationChannel", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -410,12 +382,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the notification channel. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -426,26 +397,23 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -455,9 +423,7 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace_async async def update( @@ -473,12 +439,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -489,16 +454,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.NotificationChannel] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.NotificationChannel] = kwargs.pop("cls", None) _notification_channel = _models.NotificationChannelFragment(tags=tags) _json = self._serialize.body(_notification_channel, "NotificationChannelFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -506,15 +469,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -523,14 +485,12 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("NotificationChannel", pipeline_response) + deserialized = self._deserialize("NotificationChannel", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def notify( # pylint: disable=inconsistent-return-statements @@ -555,12 +515,11 @@ async def notify( # pylint: disable=inconsistent-return-statements :type event_name: str or ~azure.mgmt.devtestlabs.models.NotificationChannelEventType :param json_payload: Properties for the notification in json format. Default value is None. :type json_payload: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -571,16 +530,14 @@ async def notify( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) _notify_parameters = _models.NotifyParameters(event_name=event_name, json_payload=json_payload) _json = self._serialize.body(_notify_parameters, "NotifyParameters") - request = build_notify_request( + _request = build_notify_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -588,15 +545,14 @@ async def notify( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.notify.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -606,6 +562,4 @@ async def notify( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - notify.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}/notify"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_operations.py index d8ecc67e486e..7f2a4665fadd 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, Callable, Dict, Optional, TypeVar +from typing import Any, Callable, Dict, Optional, Type, TypeVar from azure.core.exceptions import ( ClientAuthenticationError, @@ -18,20 +18,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._operations import build_get_request -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -63,12 +61,11 @@ async def get(self, location_name: str, name: str, **kwargs: Any) -> _models.Ope :type location_name: str :param name: The name of the operation. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: OperationResult or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.OperationResult :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -79,25 +76,22 @@ async def get(self, location_name: str, name: str, **kwargs: Any) -> _models.Ope _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.OperationResult] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.OperationResult] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( location_name=location_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -106,15 +100,9 @@ async def get(self, location_name: str, name: str, **kwargs: Any) -> _models.Ope map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("OperationResult", pipeline_response) - - if response.status_code == 202: - deserialized = self._deserialize("OperationResult", pipeline_response) + deserialized = self._deserialize("OperationResult", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.DevTestLab/locations/{locationName}/operations/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_policies_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_policies_operations.py index 008d0110669c..930d3deeef5c 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_policies_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_policies_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, overload +from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, Type, TypeVar, Union, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -20,15 +21,13 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._policies_operations import ( build_create_or_update_request, build_delete_request, @@ -37,10 +36,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -96,7 +95,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Policy or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Policy] :raises ~azure.core.exceptions.HttpResponseError: @@ -104,12 +102,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.PolicyList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.PolicyList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -120,7 +116,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, @@ -130,12 +126,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -147,26 +141,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("PolicyList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -178,8 +172,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies"} # type: ignore - @distributed_trace_async async def get( self, @@ -203,12 +195,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=description)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -219,12 +210,10 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Policy] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Policy] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, @@ -232,15 +221,14 @@ async def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -249,14 +237,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Policy", pipeline_response) + deserialized = self._deserialize("Policy", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}"} # type: ignore + return deserialized # type: ignore @overload async def create_or_update( @@ -285,7 +271,6 @@ async def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: @@ -298,7 +283,7 @@ async def create_or_update( lab_name: str, policy_set_name: str, name: str, - policy: IO, + policy: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -314,11 +299,10 @@ async def create_or_update( :param name: The name of the policy. Required. :type name: str :param policy: A Policy. Required. - :type policy: IO + :type policy: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: @@ -331,7 +315,7 @@ async def create_or_update( lab_name: str, policy_set_name: str, name: str, - policy: Union[_models.Policy, IO], + policy: Union[_models.Policy, IO[bytes]], **kwargs: Any ) -> _models.Policy: """Create or replace an existing policy. @@ -344,17 +328,13 @@ async def create_or_update( :type policy_set_name: str :param name: The name of the policy. Required. :type name: str - :param policy: A Policy. Is either a model type or a IO type. Required. - :type policy: ~azure.mgmt.devtestlabs.models.Policy or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param policy: A Policy. Is either a Policy type or a IO[bytes] type. Required. + :type policy: ~azure.mgmt.devtestlabs.models.Policy or IO[bytes] :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -365,21 +345,19 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Policy] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Policy] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(policy, (IO, bytes)): + if isinstance(policy, (IOBase, bytes)): _content = policy else: _json = self._serialize.body(policy, "Policy") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, @@ -389,15 +367,14 @@ async def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -406,18 +383,12 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Policy", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Policy", pipeline_response) + deserialized = self._deserialize("Policy", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -433,12 +404,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type policy_set_name: str :param name: The name of the policy. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -449,27 +419,24 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -479,9 +446,7 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace_async async def update( @@ -505,12 +470,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -521,16 +485,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Policy] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Policy] = kwargs.pop("cls", None) _policy = _models.PolicyFragment(tags=tags) _json = self._serialize.body(_policy, "PolicyFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, @@ -539,15 +501,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -556,11 +517,9 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Policy", pipeline_response) + deserialized = self._deserialize("Policy", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_policy_sets_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_policy_sets_operations.py index dd1cb56d31a2..926b73397940 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_policy_sets_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_policy_sets_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar +from typing import Any, Callable, Dict, List, Optional, Type, TypeVar from azure.core.exceptions import ( ClientAuthenticationError, @@ -18,20 +18,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._policy_sets_operations import build_evaluate_policies_request -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -74,12 +72,11 @@ async def evaluate_policies( :type name: str :param policies: Policies to evaluate. Default value is None. :type policies: list[~azure.mgmt.devtestlabs.models.EvaluatePoliciesProperties] - :keyword callable cls: A custom type or function that will be passed the direct response :return: EvaluatePoliciesResponse or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.EvaluatePoliciesResponse :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -90,16 +87,14 @@ async def evaluate_policies( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.EvaluatePoliciesResponse] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.EvaluatePoliciesResponse] = kwargs.pop("cls", None) _evaluate_policies_request = _models.EvaluatePoliciesRequest(policies=policies) _json = self._serialize.body(_evaluate_policies_request, "EvaluatePoliciesRequest") - request = build_evaluate_policies_request( + _request = build_evaluate_policies_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -107,15 +102,14 @@ async def evaluate_policies( api_version=api_version, content_type=content_type, json=_json, - template_url=self.evaluate_policies.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -124,11 +118,9 @@ async def evaluate_policies( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("EvaluatePoliciesResponse", pipeline_response) + deserialized = self._deserialize("EvaluatePoliciesResponse", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - evaluate_policies.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{name}/evaluatePolicies"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_provider_operations_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_provider_operations_operations.py index e225f5f9dba6..6a259389e3e3 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_provider_operations_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_provider_operations_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar +from typing import Any, AsyncIterable, Callable, Dict, Optional, Type, TypeVar import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -20,20 +20,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._provider_operations_operations import build_list_request -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -61,7 +59,6 @@ def __init__(self, *args, **kwargs) -> None: def list(self, **kwargs: Any) -> AsyncIterable["_models.OperationMetadata"]: """Result of the request to list REST API operations. - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either OperationMetadata or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.OperationMetadata] @@ -70,12 +67,10 @@ def list(self, **kwargs: Any) -> AsyncIterable["_models.OperationMetadata"]: _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ProviderOperationResult] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ProviderOperationResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -86,14 +81,12 @@ def list(self, **kwargs: Any) -> AsyncIterable["_models.OperationMetadata"]: def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -105,26 +98,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ProviderOperationResult", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -135,5 +128,3 @@ async def get_next(next_link=None): return pipeline_response return AsyncItemPaged(get_next, extract_data) - - list.metadata = {"url": "/providers/Microsoft.DevTestLab/operations"} # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_schedules_operations.py index 64231191e917..2b31889ac3d4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_schedules_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_schedules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._schedules_operations import ( build_create_or_update_request, build_delete_request, @@ -41,10 +42,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -97,7 +98,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -105,12 +105,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -121,7 +119,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -130,12 +128,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -147,26 +143,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -178,8 +174,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -195,12 +189,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=status)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -211,27 +204,24 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -240,14 +230,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @overload async def create_or_update( @@ -273,7 +261,6 @@ async def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -285,7 +272,7 @@ async def create_or_update( resource_group_name: str, lab_name: str, name: str, - schedule: IO, + schedule: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -299,11 +286,10 @@ async def create_or_update( :param name: The name of the schedule. Required. :type name: str :param schedule: A schedule. Required. - :type schedule: IO + :type schedule: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -311,7 +297,12 @@ async def create_or_update( @distributed_trace_async async def create_or_update( - self, resource_group_name: str, lab_name: str, name: str, schedule: Union[_models.Schedule, IO], **kwargs: Any + self, + resource_group_name: str, + lab_name: str, + name: str, + schedule: Union[_models.Schedule, IO[bytes]], + **kwargs: Any ) -> _models.Schedule: """Create or replace an existing schedule. @@ -321,17 +312,13 @@ async def create_or_update( :type lab_name: str :param name: The name of the schedule. Required. :type name: str - :param schedule: A schedule. Is either a model type or a IO type. Required. - :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param schedule: A schedule. Is either a Schedule type or a IO[bytes] type. Required. + :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO[bytes] :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -342,21 +329,19 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(schedule, (IO, bytes)): + if isinstance(schedule, (IOBase, bytes)): _content = schedule else: _json = self._serialize.body(schedule, "Schedule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -365,15 +350,14 @@ async def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -382,18 +366,12 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Schedule", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -407,12 +385,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -423,26 +400,23 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -452,9 +426,7 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace_async async def update( @@ -470,12 +442,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -486,16 +457,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) _schedule = _models.ScheduleFragment(tags=tags) _json = self._serialize.body(_schedule, "ScheduleFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -503,15 +472,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -520,19 +488,17 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore - async def _execute_initial( # pylint: disable=inconsistent-return-statements + async def _execute_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -543,38 +509,42 @@ async def _execute_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_execute_request( + _request = build_execute_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._execute_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _execute_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}/execute"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_execute( @@ -588,14 +558,6 @@ async def begin_execute( :type lab_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -603,15 +565,13 @@ async def begin_execute( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._execute_initial( # type: ignore + raw_result = await self._execute_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -621,28 +581,27 @@ async def begin_execute( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_execute.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}/execute"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def list_applicable( @@ -656,7 +615,6 @@ def list_applicable( :type lab_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -664,12 +622,10 @@ def list_applicable( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -680,18 +636,16 @@ def list_applicable( def prepare_request(next_link=None): if not next_link: - request = build_list_applicable_request( + _request = build_list_applicable_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_applicable.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -703,26 +657,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -733,5 +687,3 @@ async def get_next(next_link=None): return pipeline_response return AsyncItemPaged(get_next, extract_data) - - list_applicable.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}/listApplicable"} # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_secrets_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_secrets_operations.py index b9530db36634..f9858dbea29f 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_secrets_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_secrets_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._secrets_operations import ( build_create_or_update_request, build_delete_request, @@ -39,10 +40,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -98,7 +99,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Secret or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Secret] :raises ~azure.core.exceptions.HttpResponseError: @@ -106,12 +106,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.SecretList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.SecretList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -122,7 +120,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -132,12 +130,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -149,26 +145,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("SecretList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -180,8 +176,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets"} # type: ignore - @distributed_trace_async async def get( self, @@ -205,12 +199,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=value)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Secret or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Secret :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -221,12 +214,10 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Secret] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Secret] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -234,15 +225,14 @@ async def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -251,14 +241,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Secret", pipeline_response) + deserialized = self._deserialize("Secret", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( self, @@ -266,10 +254,10 @@ async def _create_or_update_initial( lab_name: str, user_name: str, name: str, - secret: Union[_models.Secret, IO], + secret: Union[_models.Secret, IO[bytes]], **kwargs: Any - ) -> _models.Secret: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -280,21 +268,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Secret] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(secret, (IO, bytes)): + if isinstance(secret, (IOBase, bytes)): _content = secret else: _json = self._serialize.body(secret, "Secret") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -304,35 +290,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Secret", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Secret", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -361,14 +345,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Secret or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Secret] @@ -382,7 +358,7 @@ async def begin_create_or_update( lab_name: str, user_name: str, name: str, - secret: IO, + secret: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -398,18 +374,10 @@ async def begin_create_or_update( :param name: The name of the secret. Required. :type name: str :param secret: A secret. Required. - :type secret: IO + :type secret: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either Secret or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Secret] @@ -423,7 +391,7 @@ async def begin_create_or_update( lab_name: str, user_name: str, name: str, - secret: Union[_models.Secret, IO], + secret: Union[_models.Secret, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.Secret]: """Create or replace an existing secret. This operation can take a while to complete. @@ -436,19 +404,8 @@ async def begin_create_or_update( :type user_name: str :param name: The name of the secret. Required. :type name: str - :param secret: A secret. Is either a model type or a IO type. Required. - :type secret: ~azure.mgmt.devtestlabs.models.Secret or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param secret: A secret. Is either a Secret type or a IO[bytes] type. Required. + :type secret: ~azure.mgmt.devtestlabs.models.Secret or IO[bytes] :return: An instance of AsyncLROPoller that returns either Secret or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.Secret] @@ -457,16 +414,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Secret] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Secret] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -479,30 +434,31 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Secret", pipeline_response) + deserialized = self._deserialize("Secret", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.Secret].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return AsyncLROPoller[_models.Secret]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -518,12 +474,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type user_name: str :param name: The name of the secret. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -534,27 +489,24 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -564,9 +516,7 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace_async async def update( @@ -590,12 +540,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Secret or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Secret :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -606,16 +555,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Secret] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Secret] = kwargs.pop("cls", None) _secret = _models.SecretFragment(tags=tags) _json = self._serialize.body(_secret, "SecretFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -624,15 +571,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -641,11 +587,9 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Secret", pipeline_response) + deserialized = self._deserialize("Secret", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_fabric_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_fabric_schedules_operations.py index cee26ec28292..b20b1453a6de 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_fabric_schedules_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_fabric_schedules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._service_fabric_schedules_operations import ( build_create_or_update_request, build_delete_request, @@ -40,10 +41,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -102,7 +103,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -110,12 +110,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -126,7 +124,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -137,12 +135,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -154,26 +150,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -185,8 +181,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules"} # type: ignore - @distributed_trace_async async def get( self, @@ -213,12 +207,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=status)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -229,12 +222,10 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -243,15 +234,14 @@ async def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -260,14 +250,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @overload async def create_or_update( @@ -299,7 +287,6 @@ async def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -313,7 +300,7 @@ async def create_or_update( user_name: str, service_fabric_name: str, name: str, - schedule: IO, + schedule: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -331,11 +318,10 @@ async def create_or_update( :param name: The name of the schedule. Required. :type name: str :param schedule: A schedule. Required. - :type schedule: IO + :type schedule: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -349,7 +335,7 @@ async def create_or_update( user_name: str, service_fabric_name: str, name: str, - schedule: Union[_models.Schedule, IO], + schedule: Union[_models.Schedule, IO[bytes]], **kwargs: Any ) -> _models.Schedule: """Create or replace an existing schedule. @@ -364,17 +350,13 @@ async def create_or_update( :type service_fabric_name: str :param name: The name of the schedule. Required. :type name: str - :param schedule: A schedule. Is either a model type or a IO type. Required. - :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param schedule: A schedule. Is either a Schedule type or a IO[bytes] type. Required. + :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO[bytes] :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -385,21 +367,19 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(schedule, (IO, bytes)): + if isinstance(schedule, (IOBase, bytes)): _content = schedule else: _json = self._serialize.body(schedule, "Schedule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -410,15 +390,14 @@ async def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -427,18 +406,12 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Schedule", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -462,12 +435,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type service_fabric_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -478,12 +450,10 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -491,15 +461,14 @@ async def delete( # pylint: disable=inconsistent-return-statements name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -509,9 +478,7 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace_async async def update( @@ -538,12 +505,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -554,16 +520,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) _schedule = _models.ScheduleFragment(tags=tags) _json = self._serialize.body(_schedule, "ScheduleFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -573,15 +537,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -590,16 +553,14 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore - async def _execute_initial( # pylint: disable=inconsistent-return-statements + async def _execute_initial( self, resource_group_name: str, lab_name: str, @@ -607,8 +568,8 @@ async def _execute_initial( # pylint: disable=inconsistent-return-statements service_fabric_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -619,12 +580,10 @@ async def _execute_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_execute_request( + _request = build_execute_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -632,27 +591,33 @@ async def _execute_initial( # pylint: disable=inconsistent-return-statements name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._execute_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _execute_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}/execute"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_execute( @@ -676,14 +641,6 @@ async def begin_execute( :type service_fabric_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -691,15 +648,13 @@ async def begin_execute( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._execute_initial( # type: ignore + raw_result = await self._execute_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -711,25 +666,24 @@ async def begin_execute( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_execute.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}/execute"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_fabrics_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_fabrics_operations.py index 9e255d1de472..4fd11a393f02 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_fabrics_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_fabrics_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._service_fabrics_operations import ( build_create_or_update_request, build_delete_request, @@ -42,10 +43,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -101,7 +102,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ServiceFabric or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.ServiceFabric] :raises ~azure.core.exceptions.HttpResponseError: @@ -109,12 +109,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabricList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ServiceFabricList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -125,7 +123,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -135,12 +133,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -152,26 +148,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ServiceFabricList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -183,8 +179,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics"} # type: ignore - @distributed_trace_async async def get( self, @@ -208,12 +202,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($expand=applicableSchedule)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceFabric or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceFabric :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -224,12 +217,10 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabric] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ServiceFabric] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -237,15 +228,14 @@ async def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -254,14 +244,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServiceFabric", pipeline_response) + deserialized = self._deserialize("ServiceFabric", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( self, @@ -269,10 +257,10 @@ async def _create_or_update_initial( lab_name: str, user_name: str, name: str, - service_fabric: Union[_models.ServiceFabric, IO], + service_fabric: Union[_models.ServiceFabric, IO[bytes]], **kwargs: Any - ) -> _models.ServiceFabric: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -283,21 +271,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabric] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(service_fabric, (IO, bytes)): + if isinstance(service_fabric, (IOBase, bytes)): _content = service_fabric else: _json = self._serialize.body(service_fabric, "ServiceFabric") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -307,35 +293,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("ServiceFabric", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("ServiceFabric", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -364,14 +348,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either ServiceFabric or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.ServiceFabric] @@ -385,7 +361,7 @@ async def begin_create_or_update( lab_name: str, user_name: str, name: str, - service_fabric: IO, + service_fabric: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -401,18 +377,10 @@ async def begin_create_or_update( :param name: The name of the service fabric. Required. :type name: str :param service_fabric: A Service Fabric. Required. - :type service_fabric: IO + :type service_fabric: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either ServiceFabric or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.ServiceFabric] @@ -426,7 +394,7 @@ async def begin_create_or_update( lab_name: str, user_name: str, name: str, - service_fabric: Union[_models.ServiceFabric, IO], + service_fabric: Union[_models.ServiceFabric, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.ServiceFabric]: """Create or replace an existing service fabric. This operation can take a while to complete. @@ -439,19 +407,9 @@ async def begin_create_or_update( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :param service_fabric: A Service Fabric. Is either a model type or a IO type. Required. - :type service_fabric: ~azure.mgmt.devtestlabs.models.ServiceFabric or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param service_fabric: A Service Fabric. Is either a ServiceFabric type or a IO[bytes] type. + Required. + :type service_fabric: ~azure.mgmt.devtestlabs.models.ServiceFabric or IO[bytes] :return: An instance of AsyncLROPoller that returns either ServiceFabric or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.ServiceFabric] @@ -460,16 +418,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabric] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.ServiceFabric] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -482,35 +438,36 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("ServiceFabric", pipeline_response) + deserialized = self._deserialize("ServiceFabric", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.ServiceFabric].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return AsyncLROPoller[_models.ServiceFabric]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -521,39 +478,43 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -569,14 +530,6 @@ async def begin_delete( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -584,15 +537,13 @@ async def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -603,28 +554,27 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def update( @@ -648,12 +598,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceFabric or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceFabric :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -664,16 +613,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabric] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.ServiceFabric] = kwargs.pop("cls", None) _service_fabric = _models.ServiceFabricFragment(tags=tags) _json = self._serialize.body(_service_fabric, "ServiceFabricFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -682,15 +629,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -699,14 +645,12 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServiceFabric", pipeline_response) + deserialized = self._deserialize("ServiceFabric", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def list_applicable_schedules( @@ -722,12 +666,11 @@ async def list_applicable_schedules( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ApplicableSchedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ApplicableSchedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -738,27 +681,24 @@ async def list_applicable_schedules( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ApplicableSchedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ApplicableSchedule] = kwargs.pop("cls", None) - request = build_list_applicable_schedules_request( + _request = build_list_applicable_schedules_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_applicable_schedules.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -767,19 +707,17 @@ async def list_applicable_schedules( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ApplicableSchedule", pipeline_response) + deserialized = self._deserialize("ApplicableSchedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - list_applicable_schedules.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/listApplicableSchedules"} # type: ignore + return deserialized # type: ignore - async def _start_initial( # pylint: disable=inconsistent-return-statements + async def _start_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -790,39 +728,43 @@ async def _start_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_start_request( + _request = build_start_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._start_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _start_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/start"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_start( @@ -838,14 +780,6 @@ async def begin_start( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -853,15 +787,13 @@ async def begin_start( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._start_initial( # type: ignore + raw_result = await self._start_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -872,33 +804,32 @@ async def begin_start( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_start.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/start"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - async def _stop_initial( # pylint: disable=inconsistent-return-statements + async def _stop_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -909,39 +840,43 @@ async def _stop_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_stop_request( + _request = build_stop_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._stop_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _stop_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/stop"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_stop( @@ -957,14 +892,6 @@ async def begin_stop( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -972,15 +899,13 @@ async def begin_stop( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._stop_initial( # type: ignore + raw_result = await self._stop_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -991,25 +916,24 @@ async def begin_stop( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_stop.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/stop"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_runners_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_runners_operations.py index 22e0bff083ae..cc9323df4200 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_runners_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_service_runners_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Optional, Type, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -18,24 +19,22 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from ... import models as _models -from ..._vendor import _convert_request from ...operations._service_runners_operations import ( build_create_or_update_request, build_delete_request, build_get_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -69,12 +68,11 @@ async def get(self, resource_group_name: str, lab_name: str, name: str, **kwargs :type lab_name: str :param name: The name of the service runner. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceRunner or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceRunner :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -85,26 +83,23 @@ async def get(self, resource_group_name: str, lab_name: str, name: str, **kwargs _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceRunner] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ServiceRunner] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -113,14 +108,12 @@ async def get(self, resource_group_name: str, lab_name: str, name: str, **kwargs map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServiceRunner", pipeline_response) + deserialized = self._deserialize("ServiceRunner", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/servicerunners/{name}"} # type: ignore + return deserialized # type: ignore @overload async def create_or_update( @@ -147,7 +140,6 @@ async def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceRunner or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceRunner :raises ~azure.core.exceptions.HttpResponseError: @@ -159,7 +151,7 @@ async def create_or_update( resource_group_name: str, lab_name: str, name: str, - service_runner: IO, + service_runner: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -174,11 +166,10 @@ async def create_or_update( :type name: str :param service_runner: A container for a managed identity to execute DevTest lab services. Required. - :type service_runner: IO + :type service_runner: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceRunner or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceRunner :raises ~azure.core.exceptions.HttpResponseError: @@ -190,7 +181,7 @@ async def create_or_update( resource_group_name: str, lab_name: str, name: str, - service_runner: Union[_models.ServiceRunner, IO], + service_runner: Union[_models.ServiceRunner, IO[bytes]], **kwargs: Any ) -> _models.ServiceRunner: """Create or replace an existing service runner. @@ -202,17 +193,13 @@ async def create_or_update( :param name: The name of the service runner. Required. :type name: str :param service_runner: A container for a managed identity to execute DevTest lab services. Is - either a model type or a IO type. Required. - :type service_runner: ~azure.mgmt.devtestlabs.models.ServiceRunner or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + either a ServiceRunner type or a IO[bytes] type. Required. + :type service_runner: ~azure.mgmt.devtestlabs.models.ServiceRunner or IO[bytes] :return: ServiceRunner or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceRunner :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -223,21 +210,19 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceRunner] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.ServiceRunner] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(service_runner, (IO, bytes)): + if isinstance(service_runner, (IOBase, bytes)): _content = service_runner else: _json = self._serialize.body(service_runner, "ServiceRunner") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -246,15 +231,14 @@ async def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -263,18 +247,12 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("ServiceRunner", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("ServiceRunner", pipeline_response) + deserialized = self._deserialize("ServiceRunner", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/servicerunners/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -288,12 +266,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the service runner. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -304,26 +281,23 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -333,6 +307,4 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/servicerunners/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_users_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_users_operations.py index 23aef28b03a7..d833e6a3c9f6 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_users_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_users_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._users_operations import ( build_create_or_update_request, build_delete_request, @@ -39,10 +40,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -95,7 +96,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either User or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.User] :raises ~azure.core.exceptions.HttpResponseError: @@ -103,12 +103,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.UserList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.UserList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -119,7 +117,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -128,12 +126,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -145,26 +141,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("UserList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -176,8 +172,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -193,12 +187,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=identity)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: User or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.User :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -209,27 +202,24 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.User] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.User] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -238,19 +228,17 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("User", pipeline_response) + deserialized = self._deserialize("User", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( - self, resource_group_name: str, lab_name: str, name: str, user: Union[_models.User, IO], **kwargs: Any - ) -> _models.User: - error_map = { + self, resource_group_name: str, lab_name: str, name: str, user: Union[_models.User, IO[bytes]], **kwargs: Any + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -261,21 +249,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.User] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(user, (IO, bytes)): + if isinstance(user, (IOBase, bytes)): _content = user else: _json = self._serialize.body(user, "User") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -284,35 +270,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("User", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("User", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -338,14 +322,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either User or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.User] :raises ~azure.core.exceptions.HttpResponseError: @@ -357,7 +333,7 @@ async def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - user: IO, + user: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -371,18 +347,10 @@ async def begin_create_or_update( :param name: The name of the user profile. Required. :type name: str :param user: Profile of a lab user. Required. - :type user: IO + :type user: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either User or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.User] :raises ~azure.core.exceptions.HttpResponseError: @@ -390,7 +358,7 @@ async def begin_create_or_update( @distributed_trace_async async def begin_create_or_update( - self, resource_group_name: str, lab_name: str, name: str, user: Union[_models.User, IO], **kwargs: Any + self, resource_group_name: str, lab_name: str, name: str, user: Union[_models.User, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.User]: """Create or replace an existing user profile. This operation can take a while to complete. @@ -400,19 +368,8 @@ async def begin_create_or_update( :type lab_name: str :param name: The name of the user profile. Required. :type name: str - :param user: Profile of a lab user. Is either a model type or a IO type. Required. - :type user: ~azure.mgmt.devtestlabs.models.User or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param user: Profile of a lab user. Is either a User type or a IO[bytes] type. Required. + :type user: ~azure.mgmt.devtestlabs.models.User or IO[bytes] :return: An instance of AsyncLROPoller that returns either User or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.User] :raises ~azure.core.exceptions.HttpResponseError: @@ -420,16 +377,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.User] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.User] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -441,35 +396,36 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("User", pipeline_response) + deserialized = self._deserialize("User", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.User].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return AsyncLROPoller[_models.User]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -480,38 +436,42 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -525,14 +485,6 @@ async def begin_delete( :type lab_name: str :param name: The name of the user profile. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -540,15 +492,13 @@ async def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -558,28 +508,27 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def update( @@ -595,12 +544,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: User or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.User :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -611,16 +559,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.User] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.User] = kwargs.pop("cls", None) _user = _models.UserFragment(tags=tags) _json = self._serialize.body(_user, "UserFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -628,15 +574,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -645,11 +590,9 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("User", pipeline_response) + deserialized = self._deserialize("User", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_machine_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_machine_schedules_operations.py index bd7dfe095fd7..f0da5cd9271c 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_machine_schedules_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_machine_schedules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._virtual_machine_schedules_operations import ( build_create_or_update_request, build_delete_request, @@ -40,10 +41,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -99,7 +100,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -107,12 +107,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -123,7 +121,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -133,12 +131,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -150,26 +146,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -181,8 +177,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules"} # type: ignore - @distributed_trace_async async def get( self, @@ -206,12 +200,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($select=status)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -222,12 +215,10 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -235,15 +226,14 @@ async def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -252,14 +242,12 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @overload async def create_or_update( @@ -288,7 +276,6 @@ async def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -301,7 +288,7 @@ async def create_or_update( lab_name: str, virtual_machine_name: str, name: str, - schedule: IO, + schedule: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -317,11 +304,10 @@ async def create_or_update( :param name: The name of the schedule. Required. :type name: str :param schedule: A schedule. Required. - :type schedule: IO + :type schedule: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -334,7 +320,7 @@ async def create_or_update( lab_name: str, virtual_machine_name: str, name: str, - schedule: Union[_models.Schedule, IO], + schedule: Union[_models.Schedule, IO[bytes]], **kwargs: Any ) -> _models.Schedule: """Create or replace an existing schedule. @@ -347,17 +333,13 @@ async def create_or_update( :type virtual_machine_name: str :param name: The name of the schedule. Required. :type name: str - :param schedule: A schedule. Is either a model type or a IO type. Required. - :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param schedule: A schedule. Is either a Schedule type or a IO[bytes] type. Required. + :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO[bytes] :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -368,21 +350,19 @@ async def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(schedule, (IO, bytes)): + if isinstance(schedule, (IOBase, bytes)): _content = schedule else: _json = self._serialize.body(schedule, "Schedule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -392,15 +372,14 @@ async def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -409,18 +388,12 @@ async def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Schedule", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def delete( # pylint: disable=inconsistent-return-statements @@ -436,12 +409,11 @@ async def delete( # pylint: disable=inconsistent-return-statements :type virtual_machine_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -452,27 +424,24 @@ async def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -482,9 +451,7 @@ async def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace_async async def update( @@ -508,12 +475,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -524,16 +490,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) _schedule = _models.ScheduleFragment(tags=tags) _json = self._serialize.body(_schedule, "ScheduleFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -542,15 +506,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -559,19 +522,17 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore - async def _execute_initial( # pylint: disable=inconsistent-return-statements + async def _execute_initial( self, resource_group_name: str, lab_name: str, virtual_machine_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -582,39 +543,43 @@ async def _execute_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_execute_request( + _request = build_execute_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._execute_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _execute_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}/execute"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_execute( @@ -630,14 +595,6 @@ async def begin_execute( :type virtual_machine_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -645,15 +602,13 @@ async def begin_execute( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._execute_initial( # type: ignore + raw_result = await self._execute_initial( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -664,25 +619,24 @@ async def begin_execute( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_execute.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}/execute"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_machines_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_machines_operations.py index a297bce04390..2f8d591c860d 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_machines_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_machines_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,23 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, List, Optional, TypeVar, Union, cast, overload +from typing import ( + Any, + AsyncIterable, + AsyncIterator, + Callable, + Dict, + IO, + List, + Optional, + Type, + TypeVar, + Union, + cast, + overload, +) import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +32,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +46,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._virtual_machines_operations import ( build_add_data_disk_request, build_apply_artifacts_request, @@ -52,10 +67,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -109,7 +124,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either LabVirtualMachine or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.LabVirtualMachine] @@ -118,12 +132,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachineList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabVirtualMachineList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -134,7 +146,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -143,12 +155,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -160,26 +170,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("LabVirtualMachineList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -191,8 +201,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -209,12 +217,11 @@ async def get( 'properties($expand=artifacts,computeVm,networkInterface,applicableSchedule)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabVirtualMachine or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabVirtualMachine :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -225,27 +232,24 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachine] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabVirtualMachine] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -254,24 +258,22 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) + deserialized = self._deserialize("LabVirtualMachine", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( self, resource_group_name: str, lab_name: str, name: str, - lab_virtual_machine: Union[_models.LabVirtualMachine, IO], + lab_virtual_machine: Union[_models.LabVirtualMachine, IO[bytes]], **kwargs: Any - ) -> _models.LabVirtualMachine: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -282,21 +284,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachine] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(lab_virtual_machine, (IO, bytes)): + if isinstance(lab_virtual_machine, (IOBase, bytes)): _content = lab_virtual_machine else: _json = self._serialize.body(lab_virtual_machine, "LabVirtualMachine") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -305,35 +305,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -359,14 +357,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either LabVirtualMachine or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.LabVirtualMachine] @@ -379,7 +369,7 @@ async def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - lab_virtual_machine: IO, + lab_virtual_machine: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -393,18 +383,10 @@ async def begin_create_or_update( :param name: The name of the virtual machine. Required. :type name: str :param lab_virtual_machine: A virtual machine. Required. - :type lab_virtual_machine: IO + :type lab_virtual_machine: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either LabVirtualMachine or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.LabVirtualMachine] @@ -417,7 +399,7 @@ async def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - lab_virtual_machine: Union[_models.LabVirtualMachine, IO], + lab_virtual_machine: Union[_models.LabVirtualMachine, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.LabVirtualMachine]: """Create or replace an existing virtual machine. This operation can take a while to complete. @@ -428,19 +410,9 @@ async def begin_create_or_update( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :param lab_virtual_machine: A virtual machine. Is either a model type or a IO type. Required. - :type lab_virtual_machine: ~azure.mgmt.devtestlabs.models.LabVirtualMachine or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param lab_virtual_machine: A virtual machine. Is either a LabVirtualMachine type or a + IO[bytes] type. Required. + :type lab_virtual_machine: ~azure.mgmt.devtestlabs.models.LabVirtualMachine or IO[bytes] :return: An instance of AsyncLROPoller that returns either LabVirtualMachine or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.LabVirtualMachine] @@ -449,16 +421,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachine] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.LabVirtualMachine] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -470,35 +440,36 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) + deserialized = self._deserialize("LabVirtualMachine", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.LabVirtualMachine].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return AsyncLROPoller[_models.LabVirtualMachine]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -509,38 +480,42 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -554,14 +529,6 @@ async def begin_delete( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -569,15 +536,13 @@ async def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -587,28 +552,27 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def update( @@ -624,12 +588,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabVirtualMachine or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabVirtualMachine :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -640,16 +603,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachine] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.LabVirtualMachine] = kwargs.pop("cls", None) _lab_virtual_machine = _models.LabVirtualMachineFragment(tags=tags) _json = self._serialize.body(_lab_virtual_machine, "LabVirtualMachineFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -657,15 +618,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -674,24 +634,22 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) + deserialized = self._deserialize("LabVirtualMachine", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return deserialized # type: ignore - async def _add_data_disk_initial( # pylint: disable=inconsistent-return-statements + async def _add_data_disk_initial( self, resource_group_name: str, lab_name: str, name: str, - data_disk_properties: Union[_models.DataDiskProperties, IO], + data_disk_properties: Union[_models.DataDiskProperties, IO[bytes]], **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -702,21 +660,19 @@ async def _add_data_disk_initial( # pylint: disable=inconsistent-return-stateme _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(data_disk_properties, (IO, bytes)): + if isinstance(data_disk_properties, (IOBase, bytes)): _content = data_disk_properties else: _json = self._serialize.body(data_disk_properties, "DataDiskProperties") - request = build_add_data_disk_request( + _request = build_add_data_disk_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -725,27 +681,33 @@ async def _add_data_disk_initial( # pylint: disable=inconsistent-return-stateme content_type=content_type, json=_json, content=_content, - template_url=self._add_data_disk_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _add_data_disk_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/addDataDisk"} # type: ignore + return deserialized # type: ignore @overload async def begin_add_data_disk( @@ -773,14 +735,6 @@ async def begin_add_data_disk( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -792,7 +746,7 @@ async def begin_add_data_disk( resource_group_name: str, lab_name: str, name: str, - data_disk_properties: IO, + data_disk_properties: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -808,18 +762,10 @@ async def begin_add_data_disk( :type name: str :param data_disk_properties: Request body for adding a new or existing data disk to a virtual machine. Required. - :type data_disk_properties: IO + :type data_disk_properties: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -831,7 +777,7 @@ async def begin_add_data_disk( resource_group_name: str, lab_name: str, name: str, - data_disk_properties: Union[_models.DataDiskProperties, IO], + data_disk_properties: Union[_models.DataDiskProperties, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[None]: """Attach a new or existing data disk to virtual machine. This operation can take a while to @@ -844,19 +790,8 @@ async def begin_add_data_disk( :param name: The name of the virtual machine. Required. :type name: str :param data_disk_properties: Request body for adding a new or existing data disk to a virtual - machine. Is either a model type or a IO type. Required. - :type data_disk_properties: ~azure.mgmt.devtestlabs.models.DataDiskProperties or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + machine. Is either a DataDiskProperties type or a IO[bytes] type. Required. + :type data_disk_properties: ~azure.mgmt.devtestlabs.models.DataDiskProperties or IO[bytes] :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -864,16 +799,14 @@ async def begin_add_data_disk( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._add_data_disk_initial( # type: ignore + raw_result = await self._add_data_disk_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -885,38 +818,37 @@ async def begin_add_data_disk( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_add_data_disk.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/addDataDisk"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - async def _apply_artifacts_initial( # pylint: disable=inconsistent-return-statements + async def _apply_artifacts_initial( self, resource_group_name: str, lab_name: str, name: str, artifacts: Optional[List[_models.ArtifactInstallProperties]] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -927,16 +859,14 @@ async def _apply_artifacts_initial( # pylint: disable=inconsistent-return-state _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) _apply_artifacts_request = _models.ApplyArtifactsRequest(artifacts=artifacts) _json = self._serialize.body(_apply_artifacts_request, "ApplyArtifactsRequest") - request = build_apply_artifacts_request( + _request = build_apply_artifacts_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -944,27 +874,33 @@ async def _apply_artifacts_initial( # pylint: disable=inconsistent-return-state api_version=api_version, content_type=content_type, json=_json, - template_url=self._apply_artifacts_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _apply_artifacts_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/applyArtifacts"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_apply_artifacts( @@ -985,14 +921,6 @@ async def begin_apply_artifacts( :type name: str :param artifacts: The list of artifacts to apply. Default value is None. :type artifacts: list[~azure.mgmt.devtestlabs.models.ArtifactInstallProperties] - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1000,16 +928,14 @@ async def begin_apply_artifacts( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._apply_artifacts_initial( # type: ignore + raw_result = await self._apply_artifacts_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1021,33 +947,32 @@ async def begin_apply_artifacts( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_apply_artifacts.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/applyArtifacts"} # type: ignore - - async def _claim_initial( # pylint: disable=inconsistent-return-statements + async def _claim_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1058,38 +983,42 @@ async def _claim_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_claim_request( + _request = build_claim_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._claim_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _claim_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/claim"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_claim( @@ -1103,14 +1032,6 @@ async def begin_claim( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1118,15 +1039,13 @@ async def begin_claim( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._claim_initial( # type: ignore + raw_result = await self._claim_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1136,38 +1055,37 @@ async def begin_claim( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_claim.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/claim"} # type: ignore - - async def _detach_data_disk_initial( # pylint: disable=inconsistent-return-statements + async def _detach_data_disk_initial( self, resource_group_name: str, lab_name: str, name: str, existing_lab_disk_id: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1178,16 +1096,14 @@ async def _detach_data_disk_initial( # pylint: disable=inconsistent-return-stat _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) _detach_data_disk_properties = _models.DetachDataDiskProperties(existing_lab_disk_id=existing_lab_disk_id) _json = self._serialize.body(_detach_data_disk_properties, "DetachDataDiskProperties") - request = build_detach_data_disk_request( + _request = build_detach_data_disk_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1195,27 +1111,33 @@ async def _detach_data_disk_initial( # pylint: disable=inconsistent-return-stat api_version=api_version, content_type=content_type, json=_json, - template_url=self._detach_data_disk_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _detach_data_disk_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/detachDataDisk"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_detach_data_disk( @@ -1238,14 +1160,6 @@ async def begin_detach_data_disk( :param existing_lab_disk_id: Specifies the disk resource ID to detach from virtual machine. Default value is None. :type existing_lab_disk_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1253,16 +1167,14 @@ async def begin_detach_data_disk( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._detach_data_disk_initial( # type: ignore + raw_result = await self._detach_data_disk_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1274,28 +1186,27 @@ async def begin_detach_data_disk( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_detach_data_disk.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/detachDataDisk"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def get_rdp_file_contents( @@ -1309,12 +1220,11 @@ async def get_rdp_file_contents( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: RdpConnection or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.RdpConnection :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1325,26 +1235,23 @@ async def get_rdp_file_contents( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.RdpConnection] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.RdpConnection] = kwargs.pop("cls", None) - request = build_get_rdp_file_contents_request( + _request = build_get_rdp_file_contents_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_rdp_file_contents.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1353,14 +1260,12 @@ async def get_rdp_file_contents( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("RdpConnection", pipeline_response) + deserialized = self._deserialize("RdpConnection", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get_rdp_file_contents.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/getRdpFileContents"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def list_applicable_schedules( @@ -1374,12 +1279,11 @@ async def list_applicable_schedules( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ApplicableSchedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ApplicableSchedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1390,26 +1294,23 @@ async def list_applicable_schedules( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ApplicableSchedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ApplicableSchedule] = kwargs.pop("cls", None) - request = build_list_applicable_schedules_request( + _request = build_list_applicable_schedules_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_applicable_schedules.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1418,19 +1319,17 @@ async def list_applicable_schedules( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ApplicableSchedule", pipeline_response) + deserialized = self._deserialize("ApplicableSchedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - list_applicable_schedules.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/listApplicableSchedules"} # type: ignore + return deserialized # type: ignore - async def _redeploy_initial( # pylint: disable=inconsistent-return-statements + async def _redeploy_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1441,38 +1340,42 @@ async def _redeploy_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_redeploy_request( + _request = build_redeploy_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._redeploy_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _redeploy_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/redeploy"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_redeploy( @@ -1486,14 +1389,6 @@ async def begin_redeploy( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1501,15 +1396,13 @@ async def begin_redeploy( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._redeploy_initial( # type: ignore + raw_result = await self._redeploy_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1519,33 +1412,32 @@ async def begin_redeploy( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_redeploy.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/redeploy"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - async def _resize_initial( # pylint: disable=inconsistent-return-statements + async def _resize_initial( self, resource_group_name: str, lab_name: str, name: str, size: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1556,16 +1448,14 @@ async def _resize_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) _resize_lab_virtual_machine_properties = _models.ResizeLabVirtualMachineProperties(size=size) _json = self._serialize.body(_resize_lab_virtual_machine_properties, "ResizeLabVirtualMachineProperties") - request = build_resize_request( + _request = build_resize_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1573,27 +1463,33 @@ async def _resize_initial( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self._resize_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _resize_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/resize"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_resize( @@ -1609,14 +1505,6 @@ async def begin_resize( :type name: str :param size: Specifies the size of the virtual machine. Default value is None. :type size: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1624,16 +1512,14 @@ async def begin_resize( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._resize_initial( # type: ignore + raw_result = await self._resize_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1645,33 +1531,32 @@ async def begin_resize( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_resize.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/resize"} # type: ignore - - async def _restart_initial( # pylint: disable=inconsistent-return-statements + async def _restart_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1682,38 +1567,42 @@ async def _restart_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_restart_request( + _request = build_restart_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._restart_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _restart_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/restart"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_restart( @@ -1727,14 +1616,6 @@ async def begin_restart( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1742,15 +1623,13 @@ async def begin_restart( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._restart_initial( # type: ignore + raw_result = await self._restart_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1760,33 +1639,32 @@ async def begin_restart( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_restart.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/restart"} # type: ignore - - async def _start_initial( # pylint: disable=inconsistent-return-statements + async def _start_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1797,38 +1675,42 @@ async def _start_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_start_request( + _request = build_start_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._start_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _start_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/start"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_start( @@ -1842,14 +1724,6 @@ async def begin_start( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1857,15 +1731,13 @@ async def begin_start( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._start_initial( # type: ignore + raw_result = await self._start_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1875,33 +1747,32 @@ async def begin_start( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_start.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/start"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - async def _stop_initial( # pylint: disable=inconsistent-return-statements + async def _stop_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1912,38 +1783,42 @@ async def _stop_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_stop_request( + _request = build_stop_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._stop_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _stop_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/stop"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_stop( @@ -1957,14 +1832,6 @@ async def begin_stop( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1972,15 +1839,13 @@ async def begin_stop( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._stop_initial( # type: ignore + raw_result = await self._stop_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1990,33 +1855,32 @@ async def begin_stop( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_stop.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/stop"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - async def _transfer_disks_initial( # pylint: disable=inconsistent-return-statements + async def _transfer_disks_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2027,38 +1891,42 @@ async def _transfer_disks_initial( # pylint: disable=inconsistent-return-statem _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_transfer_disks_request( + _request = build_transfer_disks_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._transfer_disks_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _transfer_disks_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/transferDisks"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_transfer_disks( @@ -2073,14 +1941,6 @@ async def begin_transfer_disks( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -2088,15 +1948,13 @@ async def begin_transfer_disks( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._transfer_disks_initial( # type: ignore + raw_result = await self._transfer_disks_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2106,33 +1964,32 @@ async def begin_transfer_disks( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_transfer_disks.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/transferDisks"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - async def _un_claim_initial( # pylint: disable=inconsistent-return-statements + async def _un_claim_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2143,38 +2000,42 @@ async def _un_claim_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_un_claim_request( + _request = build_un_claim_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._un_claim_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _un_claim_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/unClaim"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_un_claim( @@ -2188,14 +2049,6 @@ async def begin_un_claim( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -2203,15 +2056,13 @@ async def begin_un_claim( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._un_claim_initial( # type: ignore + raw_result = await self._un_claim_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2221,25 +2072,24 @@ async def begin_un_claim( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_un_claim.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/unClaim"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_networks_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_networks_operations.py index d72c561ffead..0b5c748c88a8 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_networks_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/aio/operations/_virtual_networks_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, AsyncIterable, Callable, Dict, IO, Optional, TypeVar, Union, cast, overload +from typing import Any, AsyncIterable, AsyncIterator, Callable, Dict, IO, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.async_paging import AsyncItemPaged, AsyncList @@ -17,12 +18,13 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import AsyncHttpResponse from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator import distributed_trace from azure.core.tracing.decorator_async import distributed_trace_async from azure.core.utils import case_insensitive_dict @@ -30,7 +32,6 @@ from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling from ... import models as _models -from ..._vendor import _convert_request from ...operations._virtual_networks_operations import ( build_create_or_update_request, build_delete_request, @@ -39,10 +40,10 @@ build_update_request, ) -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -95,7 +96,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either VirtualNetwork or the result of cls(response) :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.devtestlabs.models.VirtualNetwork] :raises ~azure.core.exceptions.HttpResponseError: @@ -103,12 +103,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetworkList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.VirtualNetworkList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -119,7 +117,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -128,12 +126,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -145,26 +141,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request async def extract_data(pipeline_response): deserialized = self._deserialize("VirtualNetworkList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, AsyncList(list_of_elem) async def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -176,8 +172,6 @@ async def get_next(next_link=None): return AsyncItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks"} # type: ignore - @distributed_trace_async async def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -193,12 +187,11 @@ async def get( :param expand: Specify the $expand query. Example: 'properties($expand=externalSubnets)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: VirtualNetwork or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.VirtualNetwork :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -209,27 +202,24 @@ async def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetwork] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.VirtualNetwork] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -238,24 +228,22 @@ async def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("VirtualNetwork", pipeline_response) + deserialized = self._deserialize("VirtualNetwork", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return deserialized # type: ignore async def _create_or_update_initial( self, resource_group_name: str, lab_name: str, name: str, - virtual_network: Union[_models.VirtualNetwork, IO], + virtual_network: Union[_models.VirtualNetwork, IO[bytes]], **kwargs: Any - ) -> _models.VirtualNetwork: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -266,21 +254,19 @@ async def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetwork] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(virtual_network, (IO, bytes)): + if isinstance(virtual_network, (IOBase, bytes)): _content = virtual_network else: _json = self._serialize.body(virtual_network, "VirtualNetwork") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -289,35 +275,33 @@ async def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("VirtualNetwork", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("VirtualNetwork", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return deserialized # type: ignore @overload async def begin_create_or_update( @@ -343,14 +327,6 @@ async def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either VirtualNetwork or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.VirtualNetwork] @@ -363,7 +339,7 @@ async def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - virtual_network: IO, + virtual_network: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -377,18 +353,10 @@ async def begin_create_or_update( :param name: The name of the virtual network. Required. :type name: str :param virtual_network: A virtual network. Required. - :type virtual_network: IO + :type virtual_network: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either VirtualNetwork or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.VirtualNetwork] @@ -401,7 +369,7 @@ async def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - virtual_network: Union[_models.VirtualNetwork, IO], + virtual_network: Union[_models.VirtualNetwork, IO[bytes]], **kwargs: Any ) -> AsyncLROPoller[_models.VirtualNetwork]: """Create or replace an existing virtual network. This operation can take a while to complete. @@ -412,19 +380,9 @@ async def begin_create_or_update( :type lab_name: str :param name: The name of the virtual network. Required. :type name: str - :param virtual_network: A virtual network. Is either a model type or a IO type. Required. - :type virtual_network: ~azure.mgmt.devtestlabs.models.VirtualNetwork or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param virtual_network: A virtual network. Is either a VirtualNetwork type or a IO[bytes] type. + Required. + :type virtual_network: ~azure.mgmt.devtestlabs.models.VirtualNetwork or IO[bytes] :return: An instance of AsyncLROPoller that returns either VirtualNetwork or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.devtestlabs.models.VirtualNetwork] @@ -433,16 +391,14 @@ async def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetwork] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.VirtualNetwork] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._create_or_update_initial( # type: ignore + raw_result = await self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -454,35 +410,36 @@ async def begin_create_or_update( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("VirtualNetwork", pipeline_response) + deserialized = self._deserialize("VirtualNetwork", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[_models.VirtualNetwork].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return AsyncLROPoller[_models.VirtualNetwork]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - async def _delete_initial( # pylint: disable=inconsistent-return-statements + async def _delete_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> AsyncIterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -493,38 +450,42 @@ async def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[AsyncIterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + await response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace_async async def begin_delete( @@ -538,14 +499,6 @@ async def begin_delete( :type lab_name: str :param name: The name of the virtual network. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for - this operation to not poll, or pass in your own initialized polling object for a personal - polling strategy. - :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.AsyncLROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -553,15 +506,13 @@ async def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, AsyncPollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = await self._delete_initial( # type: ignore + raw_result = await self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -571,28 +522,27 @@ async def begin_delete( params=_params, **kwargs ) + await raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) # type: AsyncPollingMethod + polling_method: AsyncPollingMethod = cast(AsyncPollingMethod, AsyncARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(AsyncPollingMethod, AsyncNoPolling()) else: polling_method = polling if cont_token: - return AsyncLROPoller.from_continuation_token( + return AsyncLROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return AsyncLROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace_async async def update( @@ -608,12 +558,11 @@ async def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: VirtualNetwork or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.VirtualNetwork :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -624,16 +573,14 @@ async def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetwork] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.VirtualNetwork] = kwargs.pop("cls", None) _virtual_network = _models.VirtualNetworkFragment(tags=tags) _json = self._serialize.body(_virtual_network, "VirtualNetworkFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -641,15 +588,14 @@ async def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = await self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -658,11 +604,9 @@ async def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("VirtualNetwork", pipeline_response) + deserialized = self._deserialize("VirtualNetwork", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/__init__.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/__init__.py index 1056d2951f76..3221909632a5 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/__init__.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/__init__.py @@ -161,7 +161,7 @@ from ._dev_test_labs_client_enums import VirtualMachineCreationSource from ._dev_test_labs_client_enums import WindowsOsState from ._patch import __all__ as _patch_all -from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import +from ._patch import * # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk __all__ = [ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/_dev_test_labs_client_enums.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/_dev_test_labs_client_enums.py index 1b1972d20bfb..2cf9b34d12ad 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/_dev_test_labs_client_enums.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/_dev_test_labs_client_enums.py @@ -114,6 +114,7 @@ class HttpStatusCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): SERVICE_UNAVAILABLE = "ServiceUnavailable" GATEWAY_TIMEOUT = "GatewayTimeout" HTTP_VERSION_NOT_SUPPORTED = "HttpVersionNotSupported" + CONTINUE_ENUM = "Continue" class LinuxOsState(str, Enum, metaclass=CaseInsensitiveEnumMeta): diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/_models_py3.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/_models_py3.py index 57f5a64b7e6f..d466048d0b1f 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/_models_py3.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/models/_models_py3.py @@ -55,7 +55,7 @@ class Resource(_serialization.Model): "tags": {"key": "tags", "type": "{str}"}, } - def __init__(self, *, location: Optional[str] = None, tags: Optional[Dict[str, str]] = None, **kwargs): + def __init__(self, *, location: Optional[str] = None, tags: Optional[Dict[str, str]] = None, **kwargs: Any) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -71,7 +71,8 @@ def __init__(self, *, location: Optional[str] = None, tags: Optional[Dict[str, s class ApplicableSchedule(Resource): - """Schedules applicable to a virtual machine. The schedules may have been defined on a VM or on lab level. + """Schedules applicable to a virtual machine. The schedules may have been defined on a VM or on + lab level. Variables are only populated by the server, and will be ignored when sending a request. @@ -116,8 +117,8 @@ def __init__( tags: Optional[Dict[str, str]] = None, lab_vms_shutdown: Optional["_models.Schedule"] = None, lab_vms_startup: Optional["_models.Schedule"] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -146,7 +147,7 @@ class UpdateResource(_serialization.Model): "tags": {"key": "tags", "type": "{str}"}, } - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): + def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs: Any) -> None: """ :keyword tags: The tags of the resource. :paramtype tags: dict[str, str] @@ -156,23 +157,13 @@ def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): class ApplicableScheduleFragment(UpdateResource): - """Schedules applicable to a virtual machine. The schedules may have been defined on a VM or on lab level. + """Schedules applicable to a virtual machine. The schedules may have been defined on a VM or on + lab level. :ivar tags: The tags of the resource. :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class ApplyArtifactsRequest(_serialization.Model): """Request body for applying artifacts to a virtual machine. @@ -185,7 +176,7 @@ class ApplyArtifactsRequest(_serialization.Model): "artifacts": {"key": "artifacts", "type": "[ArtifactInstallProperties]"}, } - def __init__(self, *, artifacts: Optional[List["_models.ArtifactInstallProperties"]] = None, **kwargs): + def __init__(self, *, artifacts: Optional[List["_models.ArtifactInstallProperties"]] = None, **kwargs: Any) -> None: """ :keyword artifacts: The list of artifacts to apply. :paramtype artifacts: list[~azure.mgmt.devtestlabs.models.ArtifactInstallProperties] @@ -262,7 +253,7 @@ class ArmTemplate(Resource): # pylint: disable=too-many-instance-attributes "enabled": {"key": "properties.enabled", "type": "bool"}, } - def __init__(self, *, location: Optional[str] = None, tags: Optional[Dict[str, str]] = None, **kwargs): + def __init__(self, *, location: Optional[str] = None, tags: Optional[Dict[str, str]] = None, **kwargs: Any) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -294,7 +285,7 @@ class ArmTemplateInfo(_serialization.Model): "parameters": {"key": "parameters", "type": "object"}, } - def __init__(self, *, template: Optional[JSON] = None, parameters: Optional[JSON] = None, **kwargs): + def __init__(self, *, template: Optional[JSON] = None, parameters: Optional[JSON] = None, **kwargs: Any) -> None: """ :keyword template: The template's contents. :paramtype template: JSON @@ -321,8 +312,8 @@ class ArmTemplateList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.ArmTemplate"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, *, value: Optional[List["_models.ArmTemplate"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.ArmTemplate] @@ -348,7 +339,7 @@ class ArmTemplateParameterProperties(_serialization.Model): "value": {"key": "value", "type": "str"}, } - def __init__(self, *, name: Optional[str] = None, value: Optional[str] = None, **kwargs): + def __init__(self, *, name: Optional[str] = None, value: Optional[str] = None, **kwargs: Any) -> None: """ :keyword name: The name of the template parameter. :paramtype name: str @@ -423,7 +414,7 @@ class Artifact(Resource): # pylint: disable=too-many-instance-attributes "created_date": {"key": "properties.createdDate", "type": "iso-8601"}, } - def __init__(self, *, location: Optional[str] = None, tags: Optional[Dict[str, str]] = None, **kwargs): + def __init__(self, *, location: Optional[str] = None, tags: Optional[Dict[str, str]] = None, **kwargs: Any) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -464,8 +455,8 @@ def __init__( deployment_status: Optional[str] = None, artifacts_applied: Optional[int] = None, total_artifacts: Optional[int] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword deployment_status: The deployment status of the artifact. :paramtype deployment_status: str @@ -519,8 +510,8 @@ def __init__( deployment_status_message: Optional[str] = None, vm_extension_status_message: Optional[str] = None, install_time: Optional[datetime.datetime] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword artifact_id: The artifact's identifier. :paramtype artifact_id: str @@ -561,7 +552,9 @@ class ArtifactList(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.Artifact"]] = None, next_link: Optional[str] = None, **kwargs): + def __init__( + self, *, value: Optional[List["_models.Artifact"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.Artifact] @@ -587,7 +580,7 @@ class ArtifactParameterProperties(_serialization.Model): "value": {"key": "value", "type": "str"}, } - def __init__(self, *, name: Optional[str] = None, value: Optional[str] = None, **kwargs): + def __init__(self, *, name: Optional[str] = None, value: Optional[str] = None, **kwargs: Any) -> None: """ :keyword name: The name of the artifact parameter. :paramtype name: str @@ -681,8 +674,8 @@ def __init__( branch_ref: Optional[str] = None, security_token: Optional[str] = None, status: Optional[Union[str, "_models.EnableStatus"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -728,17 +721,6 @@ class ArtifactSourceFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class ArtifactSourceList(_serialization.Model): """The response of a list operation. @@ -755,8 +737,8 @@ class ArtifactSourceList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.ArtifactSource"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, *, value: Optional[List["_models.ArtifactSource"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.ArtifactSource] @@ -780,7 +762,7 @@ class AttachDiskProperties(_serialization.Model): "leased_by_lab_vm_id": {"key": "leasedByLabVmId", "type": "str"}, } - def __init__(self, *, leased_by_lab_vm_id: Optional[str] = None, **kwargs): + def __init__(self, *, leased_by_lab_vm_id: Optional[str] = None, **kwargs: Any) -> None: """ :keyword leased_by_lab_vm_id: The resource ID of the Lab virtual machine to which the disk is attached. @@ -814,8 +796,8 @@ def __init__( disk_size_gi_b: Optional[int] = None, disk_name: Optional[str] = None, disk_type: Optional[Union[str, "_models.StorageType"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword disk_size_gi_b: Size of the disk to be attached in Gibibytes. :paramtype disk_size_gi_b: int @@ -842,7 +824,7 @@ class BulkCreationParameters(_serialization.Model): "instance_count": {"key": "instanceCount", "type": "int"}, } - def __init__(self, *, instance_count: Optional[int] = None, **kwargs): + def __init__(self, *, instance_count: Optional[int] = None, **kwargs: Any) -> None: """ :keyword instance_count: The number of virtual machine instances to create. :paramtype instance_count: int @@ -878,8 +860,8 @@ def __init__( message: Optional[str] = None, target: Optional[str] = None, details: Optional[List["_models.CloudErrorBody"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword code: The error code. :paramtype code: str @@ -925,8 +907,8 @@ def __init__( disk_uri: Optional[str] = None, managed_disk_id: Optional[str] = None, disk_size_gi_b: Optional[int] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword name: Gets data disk name. :paramtype name: str @@ -968,8 +950,8 @@ def __init__( code: Optional[str] = None, display_status: Optional[str] = None, message: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword code: Gets the status Code. :paramtype code: str @@ -1023,8 +1005,8 @@ def __init__( os_disk_id: Optional[str] = None, data_disk_ids: Optional[List[str]] = None, data_disks: Optional[List["_models.ComputeDataDisk"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword statuses: Gets the statuses of the virtual machine. :paramtype statuses: list[~azure.mgmt.devtestlabs.models.ComputeVmInstanceViewStatus] @@ -1086,8 +1068,8 @@ def __init__( display_on_chart: Optional[Union[str, "_models.CostThresholdStatus"]] = None, send_notification_when_exceeded: Optional[Union[str, "_models.CostThresholdStatus"]] = None, notification_sent: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword threshold_id: The ID of the cost threshold item. :paramtype threshold_id: str @@ -1199,8 +1181,8 @@ def __init__( data_disk_storage_info: Optional[List["_models.DataDiskStorageTypeInfo"]] = None, custom_image_plan: Optional["_models.CustomImagePropertiesFromPlan"] = None, is_plan_authorized: Optional[bool] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -1249,17 +1231,6 @@ class CustomImageFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class CustomImageList(_serialization.Model): """The response of a list operation. @@ -1276,8 +1247,8 @@ class CustomImageList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.CustomImage"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, *, value: Optional[List["_models.CustomImage"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.CustomImage] @@ -1292,7 +1263,7 @@ def __init__( class CustomImagePropertiesCustom(_serialization.Model): """Properties for creating a custom image from a VHD. - All required parameters must be populated in order to send to Azure. + All required parameters must be populated in order to send to server. :ivar image_name: The image name. :vartype image_name: str @@ -1319,8 +1290,8 @@ def __init__( os_type: Union[str, "_models.CustomImageOsType"], image_name: Optional[str] = None, sys_prep: Optional[bool] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword image_name: The image name. :paramtype image_name: str @@ -1361,8 +1332,8 @@ def __init__( id: Optional[str] = None, # pylint: disable=redefined-builtin publisher: Optional[str] = None, offer: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword id: The id of the plan, equivalent to name of the plan. :paramtype id: str @@ -1402,8 +1373,8 @@ def __init__( source_vm_id: Optional[str] = None, windows_os_info: Optional["_models.WindowsOsInfo"] = None, linux_os_info: Optional["_models.LinuxOsInfo"] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword source_vm_id: The source vm identifier. :paramtype source_vm_id: str @@ -1443,8 +1414,8 @@ def __init__( attach_new_data_disk_options: Optional["_models.AttachNewDataDiskOptions"] = None, existing_lab_disk_id: Optional[str] = None, host_caching: Optional[Union[str, "_models.HostCachingOptions"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword attach_new_data_disk_options: Specifies options to attach a new disk to the virtual machine. @@ -1478,8 +1449,12 @@ class DataDiskStorageTypeInfo(_serialization.Model): } def __init__( - self, *, lun: Optional[str] = None, storage_type: Optional[Union[str, "_models.StorageType"]] = None, **kwargs - ): + self, + *, + lun: Optional[str] = None, + storage_type: Optional[Union[str, "_models.StorageType"]] = None, + **kwargs: Any + ) -> None: """ :keyword lun: Disk Lun. :paramtype lun: str @@ -1503,7 +1478,7 @@ class DayDetails(_serialization.Model): "time": {"key": "time", "type": "str"}, } - def __init__(self, *, time: Optional[str] = None, **kwargs): + def __init__(self, *, time: Optional[str] = None, **kwargs: Any) -> None: """ :keyword time: The time of day the schedule will occur. :paramtype time: str @@ -1523,7 +1498,7 @@ class DetachDataDiskProperties(_serialization.Model): "existing_lab_disk_id": {"key": "existingLabDiskId", "type": "str"}, } - def __init__(self, *, existing_lab_disk_id: Optional[str] = None, **kwargs): + def __init__(self, *, existing_lab_disk_id: Optional[str] = None, **kwargs: Any) -> None: """ :keyword existing_lab_disk_id: Specifies the disk resource ID to detach from virtual machine. :paramtype existing_lab_disk_id: str @@ -1543,7 +1518,7 @@ class DetachDiskProperties(_serialization.Model): "leased_by_lab_vm_id": {"key": "leasedByLabVmId", "type": "str"}, } - def __init__(self, *, leased_by_lab_vm_id: Optional[str] = None, **kwargs): + def __init__(self, *, leased_by_lab_vm_id: Optional[str] = None, **kwargs: Any) -> None: """ :keyword leased_by_lab_vm_id: The resource ID of the Lab VM to which the disk is attached. :paramtype leased_by_lab_vm_id: str @@ -1634,8 +1609,8 @@ def __init__( storage_account_id: Optional[str] = None, host_caching: Optional[str] = None, managed_disk_id: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -1681,17 +1656,6 @@ class DiskFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class DiskList(_serialization.Model): """The response of a list operation. @@ -1707,7 +1671,9 @@ class DiskList(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.Disk"]] = None, next_link: Optional[str] = None, **kwargs): + def __init__( + self, *, value: Optional[List["_models.Disk"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.Disk] @@ -1781,8 +1747,8 @@ def __init__( tags: Optional[Dict[str, str]] = None, deployment_properties: Optional["_models.EnvironmentDeploymentProperties"] = None, arm_template_display_name: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -1811,17 +1777,6 @@ class DtlEnvironmentFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class DtlEnvironmentList(_serialization.Model): """The response of a list operation. @@ -1838,8 +1793,8 @@ class DtlEnvironmentList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.DtlEnvironment"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, *, value: Optional[List["_models.DtlEnvironment"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.DtlEnvironment] @@ -1870,8 +1825,8 @@ def __init__( *, arm_template_id: Optional[str] = None, parameters: Optional[List["_models.ArmTemplateParameterProperties"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword arm_template_id: The Azure Resource Manager template's identifier. :paramtype arm_template_id: str @@ -1910,8 +1865,8 @@ def __init__( fact_data: Optional[str] = None, value_offset: Optional[str] = None, user_object_id: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword fact_name: The fact name. :paramtype fact_name: str @@ -1940,7 +1895,7 @@ class EvaluatePoliciesRequest(_serialization.Model): "policies": {"key": "policies", "type": "[EvaluatePoliciesProperties]"}, } - def __init__(self, *, policies: Optional[List["_models.EvaluatePoliciesProperties"]] = None, **kwargs): + def __init__(self, *, policies: Optional[List["_models.EvaluatePoliciesProperties"]] = None, **kwargs: Any) -> None: """ :keyword policies: Policies to evaluate. :paramtype policies: list[~azure.mgmt.devtestlabs.models.EvaluatePoliciesProperties] @@ -1960,7 +1915,7 @@ class EvaluatePoliciesResponse(_serialization.Model): "results": {"key": "results", "type": "[PolicySetResult]"}, } - def __init__(self, *, results: Optional[List["_models.PolicySetResult"]] = None, **kwargs): + def __init__(self, *, results: Optional[List["_models.PolicySetResult"]] = None, **kwargs: Any) -> None: """ :keyword results: Results of evaluating a policy set. :paramtype results: list[~azure.mgmt.devtestlabs.models.PolicySetResult] @@ -1981,7 +1936,9 @@ class Event(_serialization.Model): "event_name": {"key": "eventName", "type": "str"}, } - def __init__(self, *, event_name: Optional[Union[str, "_models.NotificationChannelEventType"]] = None, **kwargs): + def __init__( + self, *, event_name: Optional[Union[str, "_models.NotificationChannelEventType"]] = None, **kwargs: Any + ) -> None: """ :keyword event_name: The event type for which this notification is enabled (i.e. AutoShutdown, Cost). Known values are: "AutoShutdown" and "Cost". @@ -2012,8 +1969,8 @@ def __init__( *, blob_storage_absolute_sas_uri: Optional[str] = None, usage_start_date: Optional[datetime.datetime] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword blob_storage_absolute_sas_uri: The blob storage absolute sas uri with write permission to the container which the usage data needs to be uploaded to. @@ -2042,8 +1999,12 @@ class ExternalSubnet(_serialization.Model): } def __init__( - self, *, id: Optional[str] = None, name: Optional[str] = None, **kwargs # pylint: disable=redefined-builtin - ): + self, + *, + id: Optional[str] = None, # pylint: disable=redefined-builtin + name: Optional[str] = None, + **kwargs: Any + ) -> None: """ :keyword id: Gets or sets the identifier. :paramtype id: str @@ -2123,8 +2084,8 @@ def __init__( os_type: Optional[str] = None, formula_content: Optional["_models.LabVirtualMachineCreationParameter"] = None, vm: Optional["_models.FormulaPropertiesFromVm"] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -2157,17 +2118,6 @@ class FormulaFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class FormulaList(_serialization.Model): """The response of a list operation. @@ -2183,7 +2133,9 @@ class FormulaList(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.Formula"]] = None, next_link: Optional[str] = None, **kwargs): + def __init__( + self, *, value: Optional[List["_models.Formula"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.Formula] @@ -2206,7 +2158,7 @@ class FormulaPropertiesFromVm(_serialization.Model): "lab_vm_id": {"key": "labVmId", "type": "str"}, } - def __init__(self, *, lab_vm_id: Optional[str] = None, **kwargs): + def __init__(self, *, lab_vm_id: Optional[str] = None, **kwargs: Any) -> None: """ :keyword lab_vm_id: The identifier of the VM from which a formula is to be created. :paramtype lab_vm_id: str @@ -2284,8 +2236,8 @@ def __init__( enabled: Optional[bool] = None, plan_id: Optional[str] = None, is_plan_authorized: Optional[bool] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -2333,8 +2285,8 @@ class GalleryImageList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.GalleryImage"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, *, value: Optional[List["_models.GalleryImage"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.GalleryImage] @@ -2377,8 +2329,8 @@ def __init__( sku: Optional[str] = None, os_type: Optional[str] = None, version: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword offer: The offer of the gallery image. :paramtype offer: str @@ -2428,8 +2380,8 @@ def __init__( parameters: Optional[List["_models.ParameterInfo"]] = None, location: Optional[str] = None, file_upload_options: Optional[Union[str, "_models.FileUploadOptions"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword virtual_machine_name: The resource name of the virtual machine. :paramtype virtual_machine_name: str @@ -2460,7 +2412,7 @@ class GenerateUploadUriParameter(_serialization.Model): "blob_name": {"key": "blobName", "type": "str"}, } - def __init__(self, *, blob_name: Optional[str] = None, **kwargs): + def __init__(self, *, blob_name: Optional[str] = None, **kwargs: Any) -> None: """ :keyword blob_name: The blob name of the upload URI. :paramtype blob_name: str @@ -2480,7 +2432,7 @@ class GenerateUploadUriResponse(_serialization.Model): "upload_uri": {"key": "uploadUri", "type": "str"}, } - def __init__(self, *, upload_uri: Optional[str] = None, **kwargs): + def __init__(self, *, upload_uri: Optional[str] = None, **kwargs: Any) -> None: """ :keyword upload_uri: The upload URI for the VHD. :paramtype upload_uri: str @@ -2500,7 +2452,7 @@ class HourDetails(_serialization.Model): "minute": {"key": "minute", "type": "int"}, } - def __init__(self, *, minute: Optional[int] = None, **kwargs): + def __init__(self, *, minute: Optional[int] = None, **kwargs: Any) -> None: """ :keyword minute: Minutes of the hour the schedule will run. :paramtype minute: int @@ -2537,8 +2489,8 @@ def __init__( principal_id: Optional[str] = None, tenant_id: Optional[str] = None, client_secret_url: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword type: Managed identity. Known values are: "None", "SystemAssigned", "UserAssigned", and "SystemAssigned,UserAssigned". @@ -2558,7 +2510,8 @@ def __init__( class ImportLabVirtualMachineRequest(_serialization.Model): - """This represents the payload required to import a virtual machine from a different lab into the current one. + """This represents the payload required to import a virtual machine from a different lab into the + current one. :ivar source_virtual_machine_resource_id: The full resource ID of the virtual machine to be imported. @@ -2577,8 +2530,8 @@ def __init__( *, source_virtual_machine_resource_id: Optional[str] = None, destination_virtual_machine_name: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword source_virtual_machine_resource_id: The full resource ID of the virtual machine to be imported. @@ -2593,7 +2546,8 @@ def __init__( class InboundNatRule(_serialization.Model): - """A rule for NAT - exposing a VM's port (backendPort) on the public IP address using a load balancer. + """A rule for NAT - exposing a VM's port (backendPort) on the public IP address using a load + balancer. :ivar transport_protocol: The transport protocol for the endpoint. Known values are: "Tcp" and "Udp". @@ -2617,8 +2571,8 @@ def __init__( transport_protocol: Optional[Union[str, "_models.TransportProtocol"]] = None, frontend_port: Optional[int] = None, backend_port: Optional[int] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword transport_protocol: The transport protocol for the endpoint. Known values are: "Tcp" and "Udp". @@ -2768,8 +2722,8 @@ def __init__( # pylint: disable=too-many-locals announcement: Optional["_models.LabAnnouncementProperties"] = None, support: Optional["_models.LabSupportProperties"] = None, extended_properties: Optional[Dict[str, str]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -2870,8 +2824,8 @@ def __init__( enabled: Optional[Union[str, "_models.EnableStatus"]] = None, expiration_date: Optional[datetime.datetime] = None, expired: Optional[bool] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword title: The plain text title for the lab announcement. :paramtype title: str @@ -2972,8 +2926,8 @@ def __init__( start_date_time: Optional[datetime.datetime] = None, end_date_time: Optional[datetime.datetime] = None, created_date: Optional[datetime.datetime] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -3027,8 +2981,8 @@ def __init__( date: Optional[datetime.datetime] = None, cost: Optional[float] = None, cost_type: Optional[Union[str, "_models.CostType"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword date: The date of the cost item. :paramtype date: ~datetime.datetime @@ -3055,7 +3009,7 @@ class LabCostSummaryProperties(_serialization.Model): "estimated_lab_cost": {"key": "estimatedLabCost", "type": "float"}, } - def __init__(self, *, estimated_lab_cost: Optional[float] = None, **kwargs): + def __init__(self, *, estimated_lab_cost: Optional[float] = None, **kwargs: Any) -> None: """ :keyword estimated_lab_cost: The cost component of the cost item. :paramtype estimated_lab_cost: float @@ -3071,17 +3025,6 @@ class LabFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class LabList(_serialization.Model): """The response of a list operation. @@ -3097,7 +3040,9 @@ class LabList(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.Lab"]] = None, next_link: Optional[str] = None, **kwargs): + def __init__( + self, *, value: Optional[List["_models.Lab"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.Lab] @@ -3156,8 +3101,8 @@ def __init__( resource_status: Optional[str] = None, resource_id: Optional[str] = None, external_resource_id: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword resourcename: The name of the resource. :paramtype resourcename: str @@ -3207,8 +3152,12 @@ class LabSupportProperties(_serialization.Model): } def __init__( - self, *, enabled: Optional[Union[str, "_models.EnableStatus"]] = None, markdown: Optional[str] = None, **kwargs - ): + self, + *, + enabled: Optional[Union[str, "_models.EnableStatus"]] = None, + markdown: Optional[str] = None, + **kwargs: Any + ) -> None: """ :keyword enabled: Is the lab support banner active/enabled at this time?. Known values are: "Enabled" and "Disabled". @@ -3233,7 +3182,7 @@ class LabVhd(_serialization.Model): "id": {"key": "id", "type": "str"}, } - def __init__(self, *, id: Optional[str] = None, **kwargs): # pylint: disable=redefined-builtin + def __init__(self, *, id: Optional[str] = None, **kwargs: Any) -> None: # pylint: disable=redefined-builtin """ :keyword id: The URI to the VHD. :paramtype id: str @@ -3256,7 +3205,9 @@ class LabVhdList(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.LabVhd"]] = None, next_link: Optional[str] = None, **kwargs): + def __init__( + self, *, value: Optional[List["_models.LabVhd"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.LabVhd] @@ -3456,8 +3407,8 @@ def __init__( # pylint: disable=too-many-locals environment_id: Optional[str] = None, data_disk_parameters: Optional[List["_models.DataDiskProperties"]] = None, schedule_parameters: Optional[List["_models.ScheduleCreationParameter"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -3677,8 +3628,8 @@ def __init__( # pylint: disable=too-many-locals environment_id: Optional[str] = None, data_disk_parameters: Optional[List["_models.DataDiskProperties"]] = None, schedule_parameters: Optional[List["_models.ScheduleCreationParameter"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword name: The name of the virtual machine or environment. :paramtype name: str @@ -3777,17 +3728,6 @@ class LabVirtualMachineFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class LabVirtualMachineList(_serialization.Model): """The response of a list operation. @@ -3804,8 +3744,12 @@ class LabVirtualMachineList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.LabVirtualMachine"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, + *, + value: Optional[List["_models.LabVirtualMachine"]] = None, + next_link: Optional[str] = None, + **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.LabVirtualMachine] @@ -3830,7 +3774,7 @@ class LinuxOsInfo(_serialization.Model): "linux_os_state": {"key": "linuxOsState", "type": "str"}, } - def __init__(self, *, linux_os_state: Optional[Union[str, "_models.LinuxOsState"]] = None, **kwargs): + def __init__(self, *, linux_os_state: Optional[Union[str, "_models.LinuxOsState"]] = None, **kwargs: Any) -> None: """ :keyword linux_os_state: The state of the Linux OS (i.e. NonDeprovisioned, DeprovisionRequested, DeprovisionApplied). Known values are: "NonDeprovisioned", @@ -3895,8 +3839,8 @@ def __init__( rdp_authority: Optional[str] = None, ssh_authority: Optional[str] = None, shared_public_ip_address_configuration: Optional["_models.SharedPublicIpAddressConfiguration"] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword virtual_network_id: The resource ID of the virtual network. :paramtype virtual_network_id: str @@ -4003,8 +3947,8 @@ def __init__( notification_locale: Optional[str] = None, description: Optional[str] = None, events: Optional[List["_models.Event"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -4041,17 +3985,6 @@ class NotificationChannelFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class NotificationChannelList(_serialization.Model): """The response of a list operation. @@ -4068,8 +4001,12 @@ class NotificationChannelList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.NotificationChannel"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, + *, + value: Optional[List["_models.NotificationChannel"]] = None, + next_link: Optional[str] = None, + **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.NotificationChannel] @@ -4115,8 +4052,8 @@ def __init__( webhook_url: Optional[str] = None, email_recipient: Optional[str] = None, notification_locale: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword status: If notifications are enabled for this schedule (i.e. Enabled, Disabled). Known values are: "Enabled" and "Disabled". @@ -4160,8 +4097,8 @@ def __init__( *, event_name: Optional[Union[str, "_models.NotificationChannelEventType"]] = None, json_payload: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword event_name: The type of event (i.e. AutoShutdown, Cost). Known values are: "AutoShutdown" and "Cost". @@ -4188,7 +4125,7 @@ class OperationError(_serialization.Model): "message": {"key": "message", "type": "str"}, } - def __init__(self, *, code: Optional[str] = None, message: Optional[str] = None, **kwargs): + def __init__(self, *, code: Optional[str] = None, message: Optional[str] = None, **kwargs: Any) -> None: """ :keyword code: The error code of the operation error. :paramtype code: str @@ -4215,8 +4152,8 @@ class OperationMetadata(_serialization.Model): } def __init__( - self, *, name: Optional[str] = None, display: Optional["_models.OperationMetadataDisplay"] = None, **kwargs - ): + self, *, name: Optional[str] = None, display: Optional["_models.OperationMetadataDisplay"] = None, **kwargs: Any + ) -> None: """ :keyword name: Operation name: {provider}/{resource}/{operation}. :paramtype name: str @@ -4255,8 +4192,8 @@ def __init__( resource: Optional[str] = None, operation: Optional[str] = None, description: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword provider: Friendly name of the resource provider. :paramtype provider: str @@ -4288,8 +4225,8 @@ class OperationResult(_serialization.Model): "RequestTimeout", "Conflict", "Gone", "LengthRequired", "PreconditionFailed", "RequestEntityTooLarge", "RequestUriTooLong", "UnsupportedMediaType", "RequestedRangeNotSatisfiable", "ExpectationFailed", "UpgradeRequired", "InternalServerError", - "NotImplemented", "BadGateway", "ServiceUnavailable", "GatewayTimeout", and - "HttpVersionNotSupported". + "NotImplemented", "BadGateway", "ServiceUnavailable", "GatewayTimeout", + "HttpVersionNotSupported", and "Continue". :vartype status_code: str or ~azure.mgmt.devtestlabs.models.HttpStatusCode :ivar error: Error details for the operation in case of a failure. :vartype error: ~azure.mgmt.devtestlabs.models.OperationError @@ -4307,8 +4244,8 @@ def __init__( status: Optional[str] = None, status_code: Optional[Union[str, "_models.HttpStatusCode"]] = None, error: Optional["_models.OperationError"] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword status: The operation status. :paramtype status: str @@ -4321,8 +4258,8 @@ def __init__( "RequestTimeout", "Conflict", "Gone", "LengthRequired", "PreconditionFailed", "RequestEntityTooLarge", "RequestUriTooLong", "UnsupportedMediaType", "RequestedRangeNotSatisfiable", "ExpectationFailed", "UpgradeRequired", "InternalServerError", - "NotImplemented", "BadGateway", "ServiceUnavailable", "GatewayTimeout", and - "HttpVersionNotSupported". + "NotImplemented", "BadGateway", "ServiceUnavailable", "GatewayTimeout", + "HttpVersionNotSupported", and "Continue". :paramtype status_code: str or ~azure.mgmt.devtestlabs.models.HttpStatusCode :keyword error: Error details for the operation in case of a failure. :paramtype error: ~azure.mgmt.devtestlabs.models.OperationError @@ -4347,7 +4284,7 @@ class ParameterInfo(_serialization.Model): "value": {"key": "value", "type": "str"}, } - def __init__(self, *, name: Optional[str] = None, value: Optional[str] = None, **kwargs): + def __init__(self, *, name: Optional[str] = None, value: Optional[str] = None, **kwargs: Any) -> None: """ :keyword name: The name of the artifact parameter. :paramtype name: str @@ -4373,7 +4310,9 @@ class ParametersValueFileInfo(_serialization.Model): "parameters_value_info": {"key": "parametersValueInfo", "type": "object"}, } - def __init__(self, *, file_name: Optional[str] = None, parameters_value_info: Optional[JSON] = None, **kwargs): + def __init__( + self, *, file_name: Optional[str] = None, parameters_value_info: Optional[JSON] = None, **kwargs: Any + ) -> None: """ :keyword file_name: File name. :paramtype file_name: str @@ -4396,7 +4335,7 @@ class PercentageCostThresholdProperties(_serialization.Model): "threshold_value": {"key": "thresholdValue", "type": "float"}, } - def __init__(self, *, threshold_value: Optional[float] = None, **kwargs): + def __init__(self, *, threshold_value: Optional[float] = None, **kwargs: Any) -> None: """ :keyword threshold_value: The cost threshold value. :paramtype threshold_value: float @@ -4482,8 +4421,8 @@ def __init__( fact_data: Optional[str] = None, threshold: Optional[str] = None, evaluator_type: Optional[Union[str, "_models.PolicyEvaluatorType"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -4527,17 +4466,6 @@ class PolicyFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class PolicyList(_serialization.Model): """The response of a list operation. @@ -4553,7 +4481,9 @@ class PolicyList(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.Policy"]] = None, next_link: Optional[str] = None, **kwargs): + def __init__( + self, *, value: Optional[List["_models.Policy"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.Policy] @@ -4585,8 +4515,8 @@ def __init__( *, has_error: Optional[bool] = None, policy_violations: Optional[List["_models.PolicyViolation"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword has_error: A value indicating whether this policy set evaluation has discovered violations. @@ -4613,7 +4543,7 @@ class PolicyViolation(_serialization.Model): "message": {"key": "message", "type": "str"}, } - def __init__(self, *, code: Optional[str] = None, message: Optional[str] = None, **kwargs): + def __init__(self, *, code: Optional[str] = None, message: Optional[str] = None, **kwargs: Any) -> None: """ :keyword code: The code of the policy violation. :paramtype code: str @@ -4644,8 +4574,8 @@ def __init__( *, transport_protocol: Optional[Union[str, "_models.TransportProtocol"]] = None, backend_port: Optional[int] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword transport_protocol: Protocol type of the port. Known values are: "Tcp" and "Udp". :paramtype transport_protocol: str or ~azure.mgmt.devtestlabs.models.TransportProtocol @@ -4677,7 +4607,7 @@ class ProviderOperationResult(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.OperationMetadata"]] = None, **kwargs): + def __init__(self, *, value: Optional[List["_models.OperationMetadata"]] = None, **kwargs: Any) -> None: """ :keyword value: List of operations supported by the resource provider. :paramtype value: list[~azure.mgmt.devtestlabs.models.OperationMetadata] @@ -4698,7 +4628,7 @@ class RdpConnection(_serialization.Model): "contents": {"key": "contents", "type": "str"}, } - def __init__(self, *, contents: Optional[str] = None, **kwargs): + def __init__(self, *, contents: Optional[str] = None, **kwargs: Any) -> None: """ :keyword contents: The contents of the .rdp file. :paramtype contents: str @@ -4718,7 +4648,7 @@ class ResizeLabVirtualMachineProperties(_serialization.Model): "size": {"key": "size", "type": "str"}, } - def __init__(self, *, size: Optional[str] = None, **kwargs): + def __init__(self, *, size: Optional[str] = None, **kwargs: Any) -> None: """ :keyword size: Specifies the size of the virtual machine. :paramtype size: str @@ -4744,8 +4674,8 @@ class RetargetScheduleProperties(_serialization.Model): } def __init__( - self, *, current_resource_id: Optional[str] = None, target_resource_id: Optional[str] = None, **kwargs - ): + self, *, current_resource_id: Optional[str] = None, target_resource_id: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword current_resource_id: The resource Id of the virtual machine on which the schedule operates. @@ -4788,7 +4718,10 @@ class Schedule(Resource): # pylint: disable=too-many-instance-attributes :ivar hourly_recurrence: If the schedule will occur multiple times a day, specify the hourly recurrence. :vartype hourly_recurrence: ~azure.mgmt.devtestlabs.models.HourDetails - :ivar time_zone_id: The time zone ID (e.g. Pacific Standard time). + :ivar time_zone_id: The time zone ID (e.g. China Standard Time, Greenland Standard Time, + Pacific Standard time, etc.). The possible values for this property can be found in + ``IReadOnlyCollection TimeZoneConverter.TZConvert.KnownWindowsTimeZoneIds`` + (https://github.com/mattjohnsonpint/TimeZoneConverter/blob/main/README.md). :vartype time_zone_id: str :ivar notification_settings: Notification settings. :vartype notification_settings: ~azure.mgmt.devtestlabs.models.NotificationSettings @@ -4843,8 +4776,8 @@ def __init__( time_zone_id: Optional[str] = None, notification_settings: Optional["_models.NotificationSettings"] = None, target_resource_id: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -4864,7 +4797,10 @@ def __init__( :keyword hourly_recurrence: If the schedule will occur multiple times a day, specify the hourly recurrence. :paramtype hourly_recurrence: ~azure.mgmt.devtestlabs.models.HourDetails - :keyword time_zone_id: The time zone ID (e.g. Pacific Standard time). + :keyword time_zone_id: The time zone ID (e.g. China Standard Time, Greenland Standard Time, + Pacific Standard time, etc.). The possible values for this property can be found in + ``IReadOnlyCollection TimeZoneConverter.TZConvert.KnownWindowsTimeZoneIds`` + (https://github.com/mattjohnsonpint/TimeZoneConverter/blob/main/README.md). :paramtype time_zone_id: str :keyword notification_settings: Notification settings. :paramtype notification_settings: ~azure.mgmt.devtestlabs.models.NotificationSettings @@ -4910,7 +4846,10 @@ class ScheduleCreationParameter(_serialization.Model): # pylint: disable=too-ma :ivar hourly_recurrence: If the schedule will occur multiple times a day, specify the hourly recurrence. :vartype hourly_recurrence: ~azure.mgmt.devtestlabs.models.HourDetails - :ivar time_zone_id: The time zone ID (e.g. Pacific Standard time). + :ivar time_zone_id: The time zone ID (e.g. China Standard Time, Greenland Standard Time, + Pacific Standard time, etc.). The possible values for this property can be found in + ``IReadOnlyCollection TimeZoneConverter.TZConvert.KnownWindowsTimeZoneIds`` + (https://github.com/mattjohnsonpint/TimeZoneConverter/blob/main/README.md). :vartype time_zone_id: str :ivar notification_settings: Notification settings. :vartype notification_settings: ~azure.mgmt.devtestlabs.models.NotificationSettings @@ -4949,8 +4888,8 @@ def __init__( time_zone_id: Optional[str] = None, notification_settings: Optional["_models.NotificationSettings"] = None, target_resource_id: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword name: The name of the virtual machine or environment. :paramtype name: str @@ -4970,7 +4909,10 @@ def __init__( :keyword hourly_recurrence: If the schedule will occur multiple times a day, specify the hourly recurrence. :paramtype hourly_recurrence: ~azure.mgmt.devtestlabs.models.HourDetails - :keyword time_zone_id: The time zone ID (e.g. Pacific Standard time). + :keyword time_zone_id: The time zone ID (e.g. China Standard Time, Greenland Standard Time, + Pacific Standard time, etc.). The possible values for this property can be found in + ``IReadOnlyCollection TimeZoneConverter.TZConvert.KnownWindowsTimeZoneIds`` + (https://github.com/mattjohnsonpint/TimeZoneConverter/blob/main/README.md). :paramtype time_zone_id: str :keyword notification_settings: Notification settings. :paramtype notification_settings: ~azure.mgmt.devtestlabs.models.NotificationSettings @@ -4998,17 +4940,6 @@ class ScheduleFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class ScheduleList(_serialization.Model): """The response of a list operation. @@ -5024,7 +4955,9 @@ class ScheduleList(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.Schedule"]] = None, next_link: Optional[str] = None, **kwargs): + def __init__( + self, *, value: Optional[List["_models.Schedule"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.Schedule] @@ -5084,8 +5017,8 @@ def __init__( location: Optional[str] = None, tags: Optional[Dict[str, str]] = None, value: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -5107,17 +5040,6 @@ class SecretFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class SecretList(_serialization.Model): """The response of a list operation. @@ -5133,7 +5055,9 @@ class SecretList(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.Secret"]] = None, next_link: Optional[str] = None, **kwargs): + def __init__( + self, *, value: Optional[List["_models.Secret"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.Secret] @@ -5202,8 +5126,8 @@ def __init__( tags: Optional[Dict[str, str]] = None, external_service_fabric_id: Optional[str] = None, environment_id: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -5230,17 +5154,6 @@ class ServiceFabricFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class ServiceFabricList(_serialization.Model): """The response of a list operation. @@ -5257,8 +5170,8 @@ class ServiceFabricList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.ServiceFabric"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, *, value: Optional[List["_models.ServiceFabric"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.ServiceFabric] @@ -5310,8 +5223,8 @@ def __init__( location: Optional[str] = None, tags: Optional[Dict[str, str]] = None, identity: Optional["_models.IdentityProperties"] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -5339,8 +5252,8 @@ class ServiceRunnerList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.ServiceRunner"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, *, value: Optional[List["_models.ServiceRunner"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.ServiceRunner] @@ -5363,7 +5276,7 @@ class SharedPublicIpAddressConfiguration(_serialization.Model): "inbound_nat_rules": {"key": "inboundNatRules", "type": "[InboundNatRule]"}, } - def __init__(self, *, inbound_nat_rules: Optional[List["_models.InboundNatRule"]] = None, **kwargs): + def __init__(self, *, inbound_nat_rules: Optional[List["_models.InboundNatRule"]] = None, **kwargs: Any) -> None: """ :keyword inbound_nat_rules: The incoming NAT rules. :paramtype inbound_nat_rules: list[~azure.mgmt.devtestlabs.models.InboundNatRule] @@ -5373,7 +5286,8 @@ def __init__(self, *, inbound_nat_rules: Optional[List["_models.InboundNatRule"] class ShutdownNotificationContent(_serialization.Model): # pylint: disable=too-many-instance-attributes - """The contents of a shutdown notification. Webhooks can use this type to deserialize the request body when they get notified of an imminent shutdown. + """The contents of a shutdown notification. Webhooks can use this type to deserialize the request + body when they get notified of an imminent shutdown. :ivar skip_url: The URL to skip auto-shutdown. :vartype skip_url: str @@ -5435,8 +5349,8 @@ def __init__( subscription_id: Optional[str] = None, resource_group_name: Optional[str] = None, lab_name: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword skip_url: The URL to skip auto-shutdown. :paramtype skip_url: str @@ -5505,8 +5419,8 @@ def __init__( resource_id: Optional[str] = None, lab_subnet_name: Optional[str] = None, allow_public_ip: Optional[Union[str, "_models.UsagePermissionType"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword resource_id: The resource ID of the subnet. :paramtype resource_id: str @@ -5567,8 +5481,8 @@ def __init__( use_public_ip_address_permission: Optional[Union[str, "_models.UsagePermissionType"]] = None, shared_public_ip_address_configuration: Optional["_models.SubnetSharedPublicIpAddressConfiguration"] = None, virtual_network_pool_name: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword resource_id: The resource ID of the subnet. :paramtype resource_id: str @@ -5610,7 +5524,7 @@ class SubnetSharedPublicIpAddressConfiguration(_serialization.Model): "allowed_ports": {"key": "allowedPorts", "type": "[Port]"}, } - def __init__(self, *, allowed_ports: Optional[List["_models.Port"]] = None, **kwargs): + def __init__(self, *, allowed_ports: Optional[List["_models.Port"]] = None, **kwargs: Any) -> None: """ :keyword allowed_ports: Backend ports that virtual machines on this subnet are allowed to expose. @@ -5655,8 +5569,8 @@ def __init__( cycle_start_date_time: Optional[datetime.datetime] = None, cycle_end_date_time: Optional[datetime.datetime] = None, cycle_type: Optional[Union[str, "_models.ReportingCycleType"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword status: Target cost status. Known values are: "Enabled" and "Disabled". :paramtype status: str or ~azure.mgmt.devtestlabs.models.TargetCostStatus @@ -5736,8 +5650,8 @@ def __init__( tags: Optional[Dict[str, str]] = None, identity: Optional["_models.UserIdentity"] = None, secret_store: Optional["_models.UserSecretStore"] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -5763,17 +5677,6 @@ class UserFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class UserIdentity(_serialization.Model): """Identity attributes of a lab user. @@ -5808,8 +5711,8 @@ def __init__( tenant_id: Optional[str] = None, object_id: Optional[str] = None, app_id: Optional[str] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword principal_name: Set to the principal name / UPN of the client JWT making the request. :paramtype principal_name: str @@ -5846,7 +5749,9 @@ class UserList(_serialization.Model): "next_link": {"key": "nextLink", "type": "str"}, } - def __init__(self, *, value: Optional[List["_models.User"]] = None, next_link: Optional[str] = None, **kwargs): + def __init__( + self, *, value: Optional[List["_models.User"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.User] @@ -5872,7 +5777,9 @@ class UserSecretStore(_serialization.Model): "key_vault_id": {"key": "keyVaultId", "type": "str"}, } - def __init__(self, *, key_vault_uri: Optional[str] = None, key_vault_id: Optional[str] = None, **kwargs): + def __init__( + self, *, key_vault_uri: Optional[str] = None, key_vault_id: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword key_vault_uri: The URI of the user's Key vault. :paramtype key_vault_uri: str @@ -5953,8 +5860,8 @@ def __init__( description: Optional[str] = None, external_provider_resource_id: Optional[str] = None, subnet_overrides: Optional[List["_models.SubnetOverride"]] = None, - **kwargs - ): + **kwargs: Any + ) -> None: """ :keyword location: The location of the resource. :paramtype location: str @@ -5988,17 +5895,6 @@ class VirtualNetworkFragment(UpdateResource): :vartype tags: dict[str, str] """ - _attribute_map = { - "tags": {"key": "tags", "type": "{str}"}, - } - - def __init__(self, *, tags: Optional[Dict[str, str]] = None, **kwargs): - """ - :keyword tags: The tags of the resource. - :paramtype tags: dict[str, str] - """ - super().__init__(tags=tags, **kwargs) - class VirtualNetworkList(_serialization.Model): """The response of a list operation. @@ -6015,8 +5911,8 @@ class VirtualNetworkList(_serialization.Model): } def __init__( - self, *, value: Optional[List["_models.VirtualNetwork"]] = None, next_link: Optional[str] = None, **kwargs - ): + self, *, value: Optional[List["_models.VirtualNetwork"]] = None, next_link: Optional[str] = None, **kwargs: Any + ) -> None: """ :keyword value: Results of the list operation. :paramtype value: list[~azure.mgmt.devtestlabs.models.VirtualNetwork] @@ -6043,7 +5939,7 @@ class WeekDetails(_serialization.Model): "time": {"key": "time", "type": "str"}, } - def __init__(self, *, weekdays: Optional[List[str]] = None, time: Optional[str] = None, **kwargs): + def __init__(self, *, weekdays: Optional[List[str]] = None, time: Optional[str] = None, **kwargs: Any) -> None: """ :keyword weekdays: The days of the week for which the schedule is set (e.g. Sunday, Monday, Tuesday, etc.). @@ -6068,7 +5964,9 @@ class WindowsOsInfo(_serialization.Model): "windows_os_state": {"key": "windowsOsState", "type": "str"}, } - def __init__(self, *, windows_os_state: Optional[Union[str, "_models.WindowsOsState"]] = None, **kwargs): + def __init__( + self, *, windows_os_state: Optional[Union[str, "_models.WindowsOsState"]] = None, **kwargs: Any + ) -> None: """ :keyword windows_os_state: The state of the Windows OS (i.e. NonSysprepped, SysprepRequested, SysprepApplied). Known values are: "NonSysprepped", "SysprepRequested", and "SysprepApplied". diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/__init__.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/__init__.py index 7ccc7d9fe973..152be74a3dfb 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/__init__.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/__init__.py @@ -33,7 +33,7 @@ from ._virtual_networks_operations import VirtualNetworksOperations from ._patch import __all__ as _patch_all -from ._patch import * # type: ignore # pylint: disable=unused-wildcard-import +from ._patch import * # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk __all__ = [ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_arm_templates_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_arm_templates_operations.py index ca065e6877dc..04bcab84cec1 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_arm_templates_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_arm_templates_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar +from typing import Any, Callable, Dict, Iterable, Optional, Type, TypeVar import urllib.parse from azure.core.exceptions import ( @@ -20,20 +20,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -56,7 +54,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -71,7 +69,7 @@ def build_list_request( "artifactSourceName": _SERIALIZER.url("artifact_source_name", artifact_source_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -103,7 +101,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -119,7 +117,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -183,7 +181,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ArmTemplate or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.ArmTemplate] :raises ~azure.core.exceptions.HttpResponseError: @@ -191,12 +188,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArmTemplateList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArmTemplateList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -207,7 +202,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -217,12 +212,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -234,26 +227,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ArmTemplateList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -265,8 +258,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates"} # type: ignore - @distributed_trace def get( self, @@ -290,12 +281,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=displayName)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArmTemplate or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArmTemplate :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -306,12 +296,10 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArmTemplate] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArmTemplate] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -319,15 +307,14 @@ def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -336,11 +323,9 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ArmTemplate", pipeline_response) + deserialized = self._deserialize("ArmTemplate", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/armtemplates/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_artifact_sources_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_artifact_sources_operations.py index 99299fd41183..39cfb3264df2 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_artifact_sources_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_artifact_sources_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Iterable, Optional, Type, TypeVar, Union, overload import urllib.parse from azure.core.exceptions import ( @@ -20,20 +21,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -55,7 +54,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -69,7 +68,7 @@ def build_list_request( "labName": _SERIALIZER.url("lab_name", lab_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -100,7 +99,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -115,7 +114,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -134,8 +133,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -150,7 +149,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -169,7 +168,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -184,7 +183,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -201,8 +200,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -217,7 +216,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -278,7 +277,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ArtifactSource or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.ArtifactSource] :raises ~azure.core.exceptions.HttpResponseError: @@ -286,12 +284,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactSourceList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArtifactSourceList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -302,7 +298,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -311,12 +307,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -328,26 +322,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ArtifactSourceList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -359,8 +353,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources"} # type: ignore - @distributed_trace def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -376,12 +368,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=displayName)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -392,27 +383,24 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactSource] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArtifactSource] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -421,14 +409,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ArtifactSource", pipeline_response) + deserialized = self._deserialize("ArtifactSource", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}"} # type: ignore + return deserialized # type: ignore @overload def create_or_update( @@ -454,7 +440,6 @@ def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: @@ -466,7 +451,7 @@ def create_or_update( resource_group_name: str, lab_name: str, name: str, - artifact_source: IO, + artifact_source: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -480,11 +465,10 @@ def create_or_update( :param name: The name of the artifact source. Required. :type name: str :param artifact_source: Properties of an artifact source. Required. - :type artifact_source: IO + :type artifact_source: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: @@ -496,7 +480,7 @@ def create_or_update( resource_group_name: str, lab_name: str, name: str, - artifact_source: Union[_models.ArtifactSource, IO], + artifact_source: Union[_models.ArtifactSource, IO[bytes]], **kwargs: Any ) -> _models.ArtifactSource: """Create or replace an existing artifact source. @@ -507,18 +491,14 @@ def create_or_update( :type lab_name: str :param name: The name of the artifact source. Required. :type name: str - :param artifact_source: Properties of an artifact source. Is either a model type or a IO type. - Required. - :type artifact_source: ~azure.mgmt.devtestlabs.models.ArtifactSource or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param artifact_source: Properties of an artifact source. Is either a ArtifactSource type or a + IO[bytes] type. Required. + :type artifact_source: ~azure.mgmt.devtestlabs.models.ArtifactSource or IO[bytes] :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -529,21 +509,19 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactSource] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.ArtifactSource] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(artifact_source, (IO, bytes)): + if isinstance(artifact_source, (IOBase, bytes)): _content = artifact_source else: _json = self._serialize.body(artifact_source, "ArtifactSource") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -552,15 +530,14 @@ def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -569,18 +546,12 @@ def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("ArtifactSource", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("ArtifactSource", pipeline_response) + deserialized = self._deserialize("ArtifactSource", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -594,12 +565,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the artifact source. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -610,26 +580,23 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -639,9 +606,7 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace def update( @@ -657,12 +622,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArtifactSource or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArtifactSource :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -673,16 +637,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactSource] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.ArtifactSource] = kwargs.pop("cls", None) _artifact_source = _models.ArtifactSourceFragment(tags=tags) _json = self._serialize.body(_artifact_source, "ArtifactSourceFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -690,15 +652,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -707,11 +668,9 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ArtifactSource", pipeline_response) + deserialized = self._deserialize("ArtifactSource", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_artifacts_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_artifacts_operations.py index 31e2a637a1fc..99c1fed5ef37 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_artifacts_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_artifacts_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Iterable, Optional, Type, TypeVar, Union, overload import urllib.parse from azure.core.exceptions import ( @@ -20,20 +21,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -56,7 +55,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -71,7 +70,7 @@ def build_list_request( "artifactSourceName": _SERIALIZER.url("artifact_source_name", artifact_source_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -103,7 +102,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -119,7 +118,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -138,8 +137,8 @@ def build_generate_arm_template_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -155,7 +154,7 @@ def build_generate_arm_template_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -219,7 +218,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Artifact or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Artifact] :raises ~azure.core.exceptions.HttpResponseError: @@ -227,12 +225,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArtifactList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ArtifactList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -243,7 +239,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -253,12 +249,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -270,26 +264,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ArtifactList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -301,8 +295,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts"} # type: ignore - @distributed_trace def get( self, @@ -326,12 +318,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=title)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Artifact or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Artifact :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -342,12 +333,10 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Artifact] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Artifact] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -355,15 +344,14 @@ def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -372,14 +360,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Artifact", pipeline_response) + deserialized = self._deserialize("Artifact", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}"} # type: ignore + return deserialized # type: ignore @overload def generate_arm_template( @@ -410,7 +396,6 @@ def generate_arm_template( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArmTemplateInfo or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArmTemplateInfo :raises ~azure.core.exceptions.HttpResponseError: @@ -423,7 +408,7 @@ def generate_arm_template( lab_name: str, artifact_source_name: str, name: str, - generate_arm_template_request: IO, + generate_arm_template_request: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -441,11 +426,10 @@ def generate_arm_template( :type name: str :param generate_arm_template_request: Parameters for generating an ARM template for deploying artifacts. Required. - :type generate_arm_template_request: IO + :type generate_arm_template_request: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ArmTemplateInfo or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArmTemplateInfo :raises ~azure.core.exceptions.HttpResponseError: @@ -458,7 +442,7 @@ def generate_arm_template( lab_name: str, artifact_source_name: str, name: str, - generate_arm_template_request: Union[_models.GenerateArmTemplateRequest, IO], + generate_arm_template_request: Union[_models.GenerateArmTemplateRequest, IO[bytes]], **kwargs: Any ) -> _models.ArmTemplateInfo: """Generates an ARM template for the given artifact, uploads the required files to a storage @@ -473,18 +457,14 @@ def generate_arm_template( :param name: The name of the artifact. Required. :type name: str :param generate_arm_template_request: Parameters for generating an ARM template for deploying - artifacts. Is either a model type or a IO type. Required. + artifacts. Is either a GenerateArmTemplateRequest type or a IO[bytes] type. Required. :type generate_arm_template_request: ~azure.mgmt.devtestlabs.models.GenerateArmTemplateRequest - or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + or IO[bytes] :return: ArmTemplateInfo or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ArmTemplateInfo :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -495,21 +475,19 @@ def generate_arm_template( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ArmTemplateInfo] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.ArmTemplateInfo] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(generate_arm_template_request, (IO, bytes)): + if isinstance(generate_arm_template_request, (IOBase, bytes)): _content = generate_arm_template_request else: _json = self._serialize.body(generate_arm_template_request, "GenerateArmTemplateRequest") - request = build_generate_arm_template_request( + _request = build_generate_arm_template_request( resource_group_name=resource_group_name, lab_name=lab_name, artifact_source_name=artifact_source_name, @@ -519,15 +497,14 @@ def generate_arm_template( content_type=content_type, json=_json, content=_content, - template_url=self.generate_arm_template.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -536,11 +513,9 @@ def generate_arm_template( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ArmTemplateInfo", pipeline_response) + deserialized = self._deserialize("ArmTemplateInfo", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - generate_arm_template.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/artifactsources/{artifactSourceName}/artifacts/{name}/generateArmTemplate"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_costs_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_costs_operations.py index 3eeb08ac9cd7..f703421483ad 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_costs_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_costs_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Optional, Type, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -18,20 +19,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -51,7 +50,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -66,7 +65,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -85,8 +84,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -101,7 +100,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -148,12 +147,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($expand=labCostDetails)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabCost or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabCost :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -164,27 +162,24 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabCost] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabCost] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -193,14 +188,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("LabCost", pipeline_response) + deserialized = self._deserialize("LabCost", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}"} # type: ignore + return deserialized # type: ignore @overload def create_or_update( @@ -226,7 +219,6 @@ def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabCost or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabCost :raises ~azure.core.exceptions.HttpResponseError: @@ -238,7 +230,7 @@ def create_or_update( resource_group_name: str, lab_name: str, name: str, - lab_cost: IO, + lab_cost: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -252,11 +244,10 @@ def create_or_update( :param name: The name of the cost. Required. :type name: str :param lab_cost: A cost item. Required. - :type lab_cost: IO + :type lab_cost: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabCost or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabCost :raises ~azure.core.exceptions.HttpResponseError: @@ -264,7 +255,12 @@ def create_or_update( @distributed_trace def create_or_update( - self, resource_group_name: str, lab_name: str, name: str, lab_cost: Union[_models.LabCost, IO], **kwargs: Any + self, + resource_group_name: str, + lab_name: str, + name: str, + lab_cost: Union[_models.LabCost, IO[bytes]], + **kwargs: Any ) -> _models.LabCost: """Create or replace an existing cost. @@ -274,17 +270,13 @@ def create_or_update( :type lab_name: str :param name: The name of the cost. Required. :type name: str - :param lab_cost: A cost item. Is either a model type or a IO type. Required. - :type lab_cost: ~azure.mgmt.devtestlabs.models.LabCost or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param lab_cost: A cost item. Is either a LabCost type or a IO[bytes] type. Required. + :type lab_cost: ~azure.mgmt.devtestlabs.models.LabCost or IO[bytes] :return: LabCost or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabCost :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -295,21 +287,19 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabCost] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.LabCost] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(lab_cost, (IO, bytes)): + if isinstance(lab_cost, (IOBase, bytes)): _content = lab_cost else: _json = self._serialize.body(lab_cost, "LabCost") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -318,15 +308,14 @@ def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -335,15 +324,9 @@ def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("LabCost", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("LabCost", pipeline_response) + deserialized = self._deserialize("LabCost", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costs/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_custom_images_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_custom_images_operations.py index 7cbfdf0c3f4f..74dd12a59603 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_custom_images_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_custom_images_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -57,7 +58,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -71,7 +72,7 @@ def build_list_request( "labName": _SERIALIZER.url("lab_name", lab_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -102,7 +103,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -117,7 +118,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -136,8 +137,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -152,7 +153,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -171,7 +172,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -186,7 +187,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -203,8 +204,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -219,7 +220,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -280,7 +281,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either CustomImage or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.CustomImage] :raises ~azure.core.exceptions.HttpResponseError: @@ -288,12 +288,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImageList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.CustomImageList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -304,7 +302,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -313,12 +311,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -330,26 +326,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("CustomImageList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -361,8 +357,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages"} # type: ignore - @distributed_trace def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -378,12 +372,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=vm)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: CustomImage or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.CustomImage :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -394,27 +387,24 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImage] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.CustomImage] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -423,24 +413,22 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("CustomImage", pipeline_response) + deserialized = self._deserialize("CustomImage", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( self, resource_group_name: str, lab_name: str, name: str, - custom_image: Union[_models.CustomImage, IO], + custom_image: Union[_models.CustomImage, IO[bytes]], **kwargs: Any - ) -> _models.CustomImage: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -451,21 +439,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImage] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(custom_image, (IO, bytes)): + if isinstance(custom_image, (IOBase, bytes)): _content = custom_image else: _json = self._serialize.body(custom_image, "CustomImage") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -474,35 +460,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("CustomImage", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("CustomImage", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -528,14 +512,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either CustomImage or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.CustomImage] @@ -548,7 +524,7 @@ def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - custom_image: IO, + custom_image: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -562,18 +538,10 @@ def begin_create_or_update( :param name: The name of the custom image. Required. :type name: str :param custom_image: A custom image. Required. - :type custom_image: IO + :type custom_image: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either CustomImage or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.CustomImage] @@ -586,7 +554,7 @@ def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - custom_image: Union[_models.CustomImage, IO], + custom_image: Union[_models.CustomImage, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.CustomImage]: """Create or replace an existing custom image. This operation can take a while to complete. @@ -597,19 +565,9 @@ def begin_create_or_update( :type lab_name: str :param name: The name of the custom image. Required. :type name: str - :param custom_image: A custom image. Is either a model type or a IO type. Required. - :type custom_image: ~azure.mgmt.devtestlabs.models.CustomImage or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param custom_image: A custom image. Is either a CustomImage type or a IO[bytes] type. + Required. + :type custom_image: ~azure.mgmt.devtestlabs.models.CustomImage or IO[bytes] :return: An instance of LROPoller that returns either CustomImage or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.CustomImage] @@ -618,16 +576,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImage] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.CustomImage] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -639,35 +595,34 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("CustomImage", pipeline_response) + deserialized = self._deserialize("CustomImage", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.CustomImage].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return LROPoller[_models.CustomImage]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _delete_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -678,38 +633,42 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -721,14 +680,6 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa :type lab_name: str :param name: The name of the custom image. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -736,15 +687,13 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -754,28 +703,27 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def update( @@ -791,12 +739,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: CustomImage or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.CustomImage :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -807,16 +754,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.CustomImage] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.CustomImage] = kwargs.pop("cls", None) _custom_image = _models.CustomImageFragment(tags=tags) _json = self._serialize.body(_custom_image, "CustomImageFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -824,15 +769,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -841,11 +785,9 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("CustomImage", pipeline_response) + deserialized = self._deserialize("CustomImage", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/customimages/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_disks_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_disks_operations.py index dab2da17ceae..220dac37a453 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_disks_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_disks_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -58,7 +59,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -73,7 +74,7 @@ def build_list_request( "userName": _SERIALIZER.url("user_name", user_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -105,7 +106,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -121,7 +122,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -140,8 +141,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -157,7 +158,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -176,7 +177,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -192,7 +193,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -209,8 +210,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -226,7 +227,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -245,8 +246,8 @@ def build_attach_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -262,7 +263,7 @@ def build_attach_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -281,8 +282,8 @@ def build_detach_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -298,7 +299,7 @@ def build_detach_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -362,7 +363,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Disk or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Disk] :raises ~azure.core.exceptions.HttpResponseError: @@ -370,12 +370,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DiskList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.DiskList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -386,7 +384,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -396,12 +394,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -413,26 +409,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("DiskList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -444,8 +440,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks"} # type: ignore - @distributed_trace def get( self, @@ -469,12 +463,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=diskType)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Disk or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Disk :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -485,12 +478,10 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Disk] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Disk] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -498,15 +489,14 @@ def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -515,14 +505,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Disk", pipeline_response) + deserialized = self._deserialize("Disk", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( self, @@ -530,10 +518,10 @@ def _create_or_update_initial( lab_name: str, user_name: str, name: str, - disk: Union[_models.Disk, IO], + disk: Union[_models.Disk, IO[bytes]], **kwargs: Any - ) -> _models.Disk: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -544,21 +532,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Disk] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(disk, (IO, bytes)): + if isinstance(disk, (IOBase, bytes)): _content = disk else: _json = self._serialize.body(disk, "Disk") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -568,35 +554,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Disk", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Disk", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -625,14 +609,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Disk or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Disk] :raises ~azure.core.exceptions.HttpResponseError: @@ -645,7 +621,7 @@ def begin_create_or_update( lab_name: str, user_name: str, name: str, - disk: IO, + disk: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -661,18 +637,10 @@ def begin_create_or_update( :param name: The name of the disk. Required. :type name: str :param disk: A Disk. Required. - :type disk: IO + :type disk: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Disk or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Disk] :raises ~azure.core.exceptions.HttpResponseError: @@ -685,7 +653,7 @@ def begin_create_or_update( lab_name: str, user_name: str, name: str, - disk: Union[_models.Disk, IO], + disk: Union[_models.Disk, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.Disk]: """Create or replace an existing disk. This operation can take a while to complete. @@ -698,19 +666,8 @@ def begin_create_or_update( :type user_name: str :param name: The name of the disk. Required. :type name: str - :param disk: A Disk. Is either a model type or a IO type. Required. - :type disk: ~azure.mgmt.devtestlabs.models.Disk or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param disk: A Disk. Is either a Disk type or a IO[bytes] type. Required. + :type disk: ~azure.mgmt.devtestlabs.models.Disk or IO[bytes] :return: An instance of LROPoller that returns either Disk or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Disk] :raises ~azure.core.exceptions.HttpResponseError: @@ -718,16 +675,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Disk] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Disk] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -740,35 +695,36 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Disk", pipeline_response) + deserialized = self._deserialize("Disk", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.Disk].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return LROPoller[_models.Disk]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements + def _delete_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -779,39 +735,43 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_delete( @@ -827,14 +787,6 @@ def begin_delete( :type user_name: str :param name: The name of the disk. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -842,15 +794,13 @@ def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -861,28 +811,27 @@ def begin_delete( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def update( @@ -906,12 +855,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Disk or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Disk :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -922,16 +870,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Disk] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Disk] = kwargs.pop("cls", None) _disk = _models.DiskFragment(tags=tags) _json = self._serialize.body(_disk, "DiskFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -940,15 +886,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -957,16 +902,14 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Disk", pipeline_response) + deserialized = self._deserialize("Disk", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}"} # type: ignore + return deserialized # type: ignore - def _attach_initial( # pylint: disable=inconsistent-return-statements + def _attach_initial( self, resource_group_name: str, lab_name: str, @@ -974,8 +917,8 @@ def _attach_initial( # pylint: disable=inconsistent-return-statements name: str, leased_by_lab_vm_id: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -986,16 +929,14 @@ def _attach_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) _attach_disk_properties = _models.AttachDiskProperties(leased_by_lab_vm_id=leased_by_lab_vm_id) _json = self._serialize.body(_attach_disk_properties, "AttachDiskProperties") - request = build_attach_request( + _request = build_attach_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -1004,27 +945,33 @@ def _attach_initial( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self._attach_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _attach_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/attach"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_attach( @@ -1050,14 +997,6 @@ def begin_attach( :param leased_by_lab_vm_id: The resource ID of the Lab virtual machine to which the disk is attached. Default value is None. :type leased_by_lab_vm_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1065,16 +1004,14 @@ def begin_attach( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._attach_initial( # type: ignore + raw_result = self._attach_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -1087,30 +1024,29 @@ def begin_attach( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_attach.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/attach"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _detach_initial( # pylint: disable=inconsistent-return-statements + def _detach_initial( self, resource_group_name: str, lab_name: str, @@ -1118,8 +1054,8 @@ def _detach_initial( # pylint: disable=inconsistent-return-statements name: str, leased_by_lab_vm_id: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1130,16 +1066,14 @@ def _detach_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) _detach_disk_properties = _models.DetachDiskProperties(leased_by_lab_vm_id=leased_by_lab_vm_id) _json = self._serialize.body(_detach_disk_properties, "DetachDiskProperties") - request = build_detach_request( + _request = build_detach_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -1148,27 +1082,33 @@ def _detach_initial( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self._detach_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _detach_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/detach"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_detach( @@ -1194,14 +1134,6 @@ def begin_detach( :param leased_by_lab_vm_id: The resource ID of the Lab VM to which the disk is attached. Default value is None. :type leased_by_lab_vm_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1209,16 +1141,14 @@ def begin_detach( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._detach_initial( # type: ignore + raw_result = self._detach_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -1231,25 +1161,24 @@ def begin_detach( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_detach.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/disks/{name}/detach"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_environments_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_environments_operations.py index b46ed2a22ff7..e6a2e89de7aa 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_environments_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_environments_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -58,7 +59,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -73,7 +74,7 @@ def build_list_request( "userName": _SERIALIZER.url("user_name", user_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -105,7 +106,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -121,7 +122,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -140,8 +141,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -157,7 +158,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -176,7 +177,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -192,7 +193,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -209,8 +210,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -226,7 +227,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -290,7 +291,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either DtlEnvironment or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.DtlEnvironment] :raises ~azure.core.exceptions.HttpResponseError: @@ -298,12 +298,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironmentList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.DtlEnvironmentList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -314,7 +312,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -324,12 +322,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -341,26 +337,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("DtlEnvironmentList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -372,8 +368,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments"} # type: ignore - @distributed_trace def get( self, @@ -397,12 +391,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=deploymentProperties)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: DtlEnvironment or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.DtlEnvironment :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -413,12 +406,10 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironment] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.DtlEnvironment] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -426,15 +417,14 @@ def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -443,14 +433,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("DtlEnvironment", pipeline_response) + deserialized = self._deserialize("DtlEnvironment", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( self, @@ -458,10 +446,10 @@ def _create_or_update_initial( lab_name: str, user_name: str, name: str, - dtl_environment: Union[_models.DtlEnvironment, IO], + dtl_environment: Union[_models.DtlEnvironment, IO[bytes]], **kwargs: Any - ) -> _models.DtlEnvironment: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -472,21 +460,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironment] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(dtl_environment, (IO, bytes)): + if isinstance(dtl_environment, (IOBase, bytes)): _content = dtl_environment else: _json = self._serialize.body(dtl_environment, "DtlEnvironment") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -496,35 +482,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("DtlEnvironment", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("DtlEnvironment", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -554,14 +538,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either DtlEnvironment or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.DtlEnvironment] @@ -575,7 +551,7 @@ def begin_create_or_update( lab_name: str, user_name: str, name: str, - dtl_environment: IO, + dtl_environment: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -592,18 +568,10 @@ def begin_create_or_update( :type name: str :param dtl_environment: An environment, which is essentially an ARM template deployment. Required. - :type dtl_environment: IO + :type dtl_environment: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either DtlEnvironment or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.DtlEnvironment] @@ -617,7 +585,7 @@ def begin_create_or_update( lab_name: str, user_name: str, name: str, - dtl_environment: Union[_models.DtlEnvironment, IO], + dtl_environment: Union[_models.DtlEnvironment, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.DtlEnvironment]: """Create or replace an existing environment. This operation can take a while to complete. @@ -631,19 +599,8 @@ def begin_create_or_update( :param name: The name of the environment. Required. :type name: str :param dtl_environment: An environment, which is essentially an ARM template deployment. Is - either a model type or a IO type. Required. - :type dtl_environment: ~azure.mgmt.devtestlabs.models.DtlEnvironment or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + either a DtlEnvironment type or a IO[bytes] type. Required. + :type dtl_environment: ~azure.mgmt.devtestlabs.models.DtlEnvironment or IO[bytes] :return: An instance of LROPoller that returns either DtlEnvironment or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.DtlEnvironment] @@ -652,16 +609,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironment] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.DtlEnvironment] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -674,35 +629,36 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("DtlEnvironment", pipeline_response) + deserialized = self._deserialize("DtlEnvironment", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.DtlEnvironment].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return LROPoller[_models.DtlEnvironment]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements + def _delete_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -713,39 +669,43 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_delete( @@ -761,14 +721,6 @@ def begin_delete( :type user_name: str :param name: The name of the environment. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -776,15 +728,13 @@ def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -795,28 +745,27 @@ def begin_delete( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def update( @@ -840,12 +789,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: DtlEnvironment or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.DtlEnvironment :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -856,16 +804,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.DtlEnvironment] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.DtlEnvironment] = kwargs.pop("cls", None) _dtl_environment = _models.DtlEnvironmentFragment(tags=tags) _json = self._serialize.body(_dtl_environment, "DtlEnvironmentFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -874,15 +820,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -891,11 +836,9 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("DtlEnvironment", pipeline_response) + deserialized = self._deserialize("DtlEnvironment", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_formulas_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_formulas_operations.py index 8aa6773e6c97..a9489ea2a0f0 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_formulas_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_formulas_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -57,7 +58,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -71,7 +72,7 @@ def build_list_request( "labName": _SERIALIZER.url("lab_name", lab_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -102,7 +103,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -117,7 +118,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -136,8 +137,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -152,7 +153,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -171,7 +172,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -186,7 +187,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -203,8 +204,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -219,7 +220,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -280,7 +281,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Formula or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Formula] :raises ~azure.core.exceptions.HttpResponseError: @@ -288,12 +288,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.FormulaList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.FormulaList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -304,7 +302,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -313,12 +311,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -330,26 +326,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("FormulaList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -361,8 +357,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas"} # type: ignore - @distributed_trace def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -378,12 +372,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=description)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Formula or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Formula :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -394,27 +387,24 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Formula] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Formula] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -423,19 +413,22 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Formula", pipeline_response) + deserialized = self._deserialize("Formula", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( - self, resource_group_name: str, lab_name: str, name: str, formula: Union[_models.Formula, IO], **kwargs: Any - ) -> _models.Formula: - error_map = { + self, + resource_group_name: str, + lab_name: str, + name: str, + formula: Union[_models.Formula, IO[bytes]], + **kwargs: Any + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -446,21 +439,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Formula] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(formula, (IO, bytes)): + if isinstance(formula, (IOBase, bytes)): _content = formula else: _json = self._serialize.body(formula, "Formula") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -469,35 +460,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Formula", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Formula", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -524,14 +513,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Formula or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Formula] :raises ~azure.core.exceptions.HttpResponseError: @@ -543,7 +524,7 @@ def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - formula: IO, + formula: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -558,18 +539,10 @@ def begin_create_or_update( :type name: str :param formula: A formula for creating a VM, specifying an image base and other parameters. Required. - :type formula: IO + :type formula: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Formula or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Formula] :raises ~azure.core.exceptions.HttpResponseError: @@ -577,7 +550,12 @@ def begin_create_or_update( @distributed_trace def begin_create_or_update( - self, resource_group_name: str, lab_name: str, name: str, formula: Union[_models.Formula, IO], **kwargs: Any + self, + resource_group_name: str, + lab_name: str, + name: str, + formula: Union[_models.Formula, IO[bytes]], + **kwargs: Any ) -> LROPoller[_models.Formula]: """Create or replace an existing formula. This operation can take a while to complete. @@ -588,19 +566,8 @@ def begin_create_or_update( :param name: The name of the formula. Required. :type name: str :param formula: A formula for creating a VM, specifying an image base and other parameters. Is - either a model type or a IO type. Required. - :type formula: ~azure.mgmt.devtestlabs.models.Formula or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + either a Formula type or a IO[bytes] type. Required. + :type formula: ~azure.mgmt.devtestlabs.models.Formula or IO[bytes] :return: An instance of LROPoller that returns either Formula or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Formula] :raises ~azure.core.exceptions.HttpResponseError: @@ -608,16 +575,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Formula] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Formula] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -629,30 +594,31 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Formula", pipeline_response) + deserialized = self._deserialize("Formula", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.Formula].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return LROPoller[_models.Formula]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -666,12 +632,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the formula. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -682,26 +647,23 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -711,9 +673,7 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace def update( @@ -729,12 +689,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Formula or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Formula :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -745,16 +704,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Formula] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Formula] = kwargs.pop("cls", None) _formula = _models.FormulaFragment(tags=tags) _json = self._serialize.body(_formula, "FormulaFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -762,15 +719,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -779,11 +735,9 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Formula", pipeline_response) + deserialized = self._deserialize("Formula", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_gallery_images_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_gallery_images_operations.py index 1e8a55fdd5dc..260744151448 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_gallery_images_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_gallery_images_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar +from typing import Any, Callable, Dict, Iterable, Optional, Type, TypeVar import urllib.parse from azure.core.exceptions import ( @@ -20,20 +20,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -55,7 +53,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -69,7 +67,7 @@ def build_list_request( "labName": _SERIALIZER.url("lab_name", lab_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -136,7 +134,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either GalleryImage or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.GalleryImage] :raises ~azure.core.exceptions.HttpResponseError: @@ -144,12 +141,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.GalleryImageList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.GalleryImageList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -160,7 +155,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -169,12 +164,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -186,26 +179,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("GalleryImageList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -216,5 +209,3 @@ def get_next(next_link=None): return pipeline_response return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/galleryimages"} # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_global_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_global_schedules_operations.py index 4fc979478875..fdff9977a6b3 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_global_schedules_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_global_schedules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -55,7 +56,7 @@ def build_list_by_subscription_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -64,7 +65,7 @@ def build_list_by_subscription_request( "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -96,7 +97,7 @@ def build_list_by_resource_group_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -109,7 +110,7 @@ def build_list_by_resource_group_request( "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -134,7 +135,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -148,7 +149,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -167,8 +168,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -182,7 +183,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -199,7 +200,7 @@ def build_delete_request(resource_group_name: str, name: str, subscription_id: s _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -213,7 +214,7 @@ def build_delete_request(resource_group_name: str, name: str, subscription_id: s "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -228,8 +229,8 @@ def build_update_request(resource_group_name: str, name: str, subscription_id: s _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -243,7 +244,7 @@ def build_update_request(resource_group_name: str, name: str, subscription_id: s "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -260,7 +261,7 @@ def build_execute_request(resource_group_name: str, name: str, subscription_id: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -274,7 +275,7 @@ def build_execute_request(resource_group_name: str, name: str, subscription_id: "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -289,8 +290,8 @@ def build_retarget_request(resource_group_name: str, name: str, subscription_id: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -304,7 +305,7 @@ def build_retarget_request(resource_group_name: str, name: str, subscription_id: "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -359,7 +360,6 @@ def list_by_subscription( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -367,12 +367,10 @@ def list_by_subscription( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -383,19 +381,17 @@ def list_by_subscription( def prepare_request(next_link=None): if not next_link: - request = build_list_by_subscription_request( + _request = build_list_by_subscription_request( subscription_id=self._config.subscription_id, expand=expand, filter=filter, top=top, orderby=orderby, api_version=api_version, - template_url=self.list_by_subscription.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -407,26 +403,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -438,8 +434,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_subscription.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.DevTestLab/schedules"} # type: ignore - @distributed_trace def list_by_resource_group( self, @@ -466,7 +460,6 @@ def list_by_resource_group( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -474,12 +467,10 @@ def list_by_resource_group( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -490,7 +481,7 @@ def list_by_resource_group( def prepare_request(next_link=None): if not next_link: - request = build_list_by_resource_group_request( + _request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, expand=expand, @@ -498,12 +489,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -515,26 +504,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -546,8 +535,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules"} # type: ignore - @distributed_trace def get(self, resource_group_name: str, name: str, expand: Optional[str] = None, **kwargs: Any) -> _models.Schedule: """Get schedule. @@ -559,12 +546,11 @@ def get(self, resource_group_name: str, name: str, expand: Optional[str] = None, :param expand: Specify the $expand query. Example: 'properties($select=status)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -575,26 +561,23 @@ def get(self, resource_group_name: str, name: str, expand: Optional[str] = None, _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -603,14 +586,12 @@ def get(self, resource_group_name: str, name: str, expand: Optional[str] = None, map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}"} # type: ignore + return deserialized # type: ignore @overload def create_or_update( @@ -633,7 +614,6 @@ def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -644,7 +624,7 @@ def create_or_update( self, resource_group_name: str, name: str, - schedule: IO, + schedule: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -656,11 +636,10 @@ def create_or_update( :param name: The name of the schedule. Required. :type name: str :param schedule: A schedule. Required. - :type schedule: IO + :type schedule: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -668,7 +647,7 @@ def create_or_update( @distributed_trace def create_or_update( - self, resource_group_name: str, name: str, schedule: Union[_models.Schedule, IO], **kwargs: Any + self, resource_group_name: str, name: str, schedule: Union[_models.Schedule, IO[bytes]], **kwargs: Any ) -> _models.Schedule: """Create or replace an existing schedule. @@ -676,17 +655,13 @@ def create_or_update( :type resource_group_name: str :param name: The name of the schedule. Required. :type name: str - :param schedule: A schedule. Is either a model type or a IO type. Required. - :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param schedule: A schedule. Is either a Schedule type or a IO[bytes] type. Required. + :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO[bytes] :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -697,21 +672,19 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(schedule, (IO, bytes)): + if isinstance(schedule, (IOBase, bytes)): _content = schedule else: _json = self._serialize.body(schedule, "Schedule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, @@ -719,15 +692,14 @@ def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -736,18 +708,12 @@ def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Schedule", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -759,12 +725,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type resource_group_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -775,25 +740,22 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -803,9 +765,7 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace def update( @@ -819,12 +779,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -835,31 +794,28 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) _schedule = _models.ScheduleFragment(tags=tags) _json = self._serialize.body(_schedule, "ScheduleFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -868,19 +824,15 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized + return deserialized # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}"} # type: ignore - - def _execute_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _execute_initial(self, resource_group_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -891,37 +843,41 @@ def _execute_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_execute_request( + _request = build_execute_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._execute_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _execute_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/execute"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_execute(self, resource_group_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -931,14 +887,6 @@ def begin_execute(self, resource_group_name: str, name: str, **kwargs: Any) -> L :type resource_group_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -946,15 +894,13 @@ def begin_execute(self, resource_group_name: str, name: str, **kwargs: Any) -> L _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._execute_initial( # type: ignore + raw_result = self._execute_initial( resource_group_name=resource_group_name, name=name, api_version=api_version, @@ -963,38 +909,37 @@ def begin_execute(self, resource_group_name: str, name: str, **kwargs: Any) -> L params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_execute.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/execute"} # type: ignore - - def _retarget_initial( # pylint: disable=inconsistent-return-statements + def _retarget_initial( self, resource_group_name: str, name: str, current_resource_id: Optional[str] = None, target_resource_id: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1005,45 +950,49 @@ def _retarget_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) _retarget_schedule_properties = _models.RetargetScheduleProperties( current_resource_id=current_resource_id, target_resource_id=target_resource_id ) _json = self._serialize.body(_retarget_schedule_properties, "RetargetScheduleProperties") - request = build_retarget_request( + _request = build_retarget_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._retarget_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _retarget_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/retarget"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_retarget( @@ -1066,14 +1015,6 @@ def begin_retarget( :param target_resource_id: The resource Id of the virtual machine that the schedule should be retargeted to. Default value is None. :type target_resource_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1081,16 +1022,14 @@ def begin_retarget( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._retarget_initial( # type: ignore + raw_result = self._retarget_initial( resource_group_name=resource_group_name, name=name, current_resource_id=current_resource_id, @@ -1102,25 +1041,24 @@ def begin_retarget( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_retarget.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/retarget"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_labs_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_labs_operations.py index 8d4bfa4f3422..b62bc53f7ebd 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_labs_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_labs_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,8 +7,9 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import datetime +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -17,13 +18,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -31,12 +33,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -56,7 +57,7 @@ def build_list_by_subscription_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -65,7 +66,7 @@ def build_list_by_subscription_request( "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -97,7 +98,7 @@ def build_list_by_resource_group_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -110,7 +111,7 @@ def build_list_by_resource_group_request( "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -135,7 +136,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -149,7 +150,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -168,8 +169,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -183,7 +184,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -200,7 +201,7 @@ def build_delete_request(resource_group_name: str, name: str, subscription_id: s _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -214,7 +215,7 @@ def build_delete_request(resource_group_name: str, name: str, subscription_id: s "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -229,8 +230,8 @@ def build_update_request(resource_group_name: str, name: str, subscription_id: s _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -244,7 +245,7 @@ def build_update_request(resource_group_name: str, name: str, subscription_id: s "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -261,7 +262,7 @@ def build_claim_any_vm_request(resource_group_name: str, name: str, subscription _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -275,7 +276,7 @@ def build_claim_any_vm_request(resource_group_name: str, name: str, subscription "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -292,8 +293,8 @@ def build_create_environment_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -307,7 +308,7 @@ def build_create_environment_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -326,8 +327,8 @@ def build_export_resource_usage_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -341,7 +342,7 @@ def build_export_resource_usage_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -360,8 +361,8 @@ def build_generate_upload_uri_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -375,7 +376,7 @@ def build_generate_upload_uri_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -394,8 +395,8 @@ def build_import_virtual_machine_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -409,7 +410,7 @@ def build_import_virtual_machine_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -426,7 +427,7 @@ def build_list_vhds_request(resource_group_name: str, name: str, subscription_id _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -440,7 +441,7 @@ def build_list_vhds_request(resource_group_name: str, name: str, subscription_id "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -493,7 +494,6 @@ def list_by_subscription( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Lab or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -501,12 +501,10 @@ def list_by_subscription( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -517,19 +515,17 @@ def list_by_subscription( def prepare_request(next_link=None): if not next_link: - request = build_list_by_subscription_request( + _request = build_list_by_subscription_request( subscription_id=self._config.subscription_id, expand=expand, filter=filter, top=top, orderby=orderby, api_version=api_version, - template_url=self.list_by_subscription.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -541,26 +537,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("LabList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -572,8 +568,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_subscription.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.DevTestLab/labs"} # type: ignore - @distributed_trace def list_by_resource_group( self, @@ -600,7 +594,6 @@ def list_by_resource_group( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Lab or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -608,12 +601,10 @@ def list_by_resource_group( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -624,7 +615,7 @@ def list_by_resource_group( def prepare_request(next_link=None): if not next_link: - request = build_list_by_resource_group_request( + _request = build_list_by_resource_group_request( resource_group_name=resource_group_name, subscription_id=self._config.subscription_id, expand=expand, @@ -632,12 +623,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list_by_resource_group.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -649,26 +638,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("LabList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -680,8 +669,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list_by_resource_group.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs"} # type: ignore - @distributed_trace def get(self, resource_group_name: str, name: str, expand: Optional[str] = None, **kwargs: Any) -> _models.Lab: """Get lab. @@ -693,12 +680,11 @@ def get(self, resource_group_name: str, name: str, expand: Optional[str] = None, :param expand: Specify the $expand query. Example: 'properties($select=defaultStorageAccount)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Lab or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Lab :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -709,26 +695,23 @@ def get(self, resource_group_name: str, name: str, expand: Optional[str] = None, _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Lab] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Lab] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -737,19 +720,17 @@ def get(self, resource_group_name: str, name: str, expand: Optional[str] = None, map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Lab", pipeline_response) + deserialized = self._deserialize("Lab", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( - self, resource_group_name: str, name: str, lab: Union[_models.Lab, IO], **kwargs: Any - ) -> _models.Lab: - error_map = { + self, resource_group_name: str, name: str, lab: Union[_models.Lab, IO[bytes]], **kwargs: Any + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -760,21 +741,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Lab] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(lab, (IO, bytes)): + if isinstance(lab, (IOBase, bytes)): _content = lab else: _json = self._serialize.body(lab, "Lab") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, @@ -782,35 +761,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Lab", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Lab", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -833,14 +810,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Lab or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -848,7 +817,13 @@ def begin_create_or_update( @overload def begin_create_or_update( - self, resource_group_name: str, name: str, lab: IO, *, content_type: str = "application/json", **kwargs: Any + self, + resource_group_name: str, + name: str, + lab: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any ) -> LROPoller[_models.Lab]: """Create or replace an existing lab. This operation can take a while to complete. @@ -857,18 +832,10 @@ def begin_create_or_update( :param name: The name of the lab. Required. :type name: str :param lab: A lab. Required. - :type lab: IO + :type lab: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Lab or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -876,7 +843,7 @@ def begin_create_or_update( @distributed_trace def begin_create_or_update( - self, resource_group_name: str, name: str, lab: Union[_models.Lab, IO], **kwargs: Any + self, resource_group_name: str, name: str, lab: Union[_models.Lab, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.Lab]: """Create or replace an existing lab. This operation can take a while to complete. @@ -884,19 +851,8 @@ def begin_create_or_update( :type resource_group_name: str :param name: The name of the lab. Required. :type name: str - :param lab: A lab. Is either a model type or a IO type. Required. - :type lab: ~azure.mgmt.devtestlabs.models.Lab or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param lab: A lab. Is either a Lab type or a IO[bytes] type. Required. + :type lab: ~azure.mgmt.devtestlabs.models.Lab or IO[bytes] :return: An instance of LROPoller that returns either Lab or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Lab] :raises ~azure.core.exceptions.HttpResponseError: @@ -904,16 +860,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Lab] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Lab] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, name=name, lab=lab, @@ -924,35 +878,32 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Lab", pipeline_response) + deserialized = self._deserialize("Lab", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.Lab].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return LROPoller[_models.Lab](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _delete_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _delete_initial(self, resource_group_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -963,37 +914,41 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_delete(self, resource_group_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -1003,14 +958,6 @@ def begin_delete(self, resource_group_name: str, name: str, **kwargs: Any) -> LR :type resource_group_name: str :param name: The name of the lab. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1018,15 +965,13 @@ def begin_delete(self, resource_group_name: str, name: str, **kwargs: Any) -> LR _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, name=name, api_version=api_version, @@ -1035,28 +980,27 @@ def begin_delete(self, resource_group_name: str, name: str, **kwargs: Any) -> LR params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def update( @@ -1070,12 +1014,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Lab or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Lab :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1086,31 +1029,28 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Lab] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Lab] = kwargs.pop("cls", None) _lab = _models.LabFragment(tags=tags) _json = self._serialize.body(_lab, "LabFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1119,19 +1059,15 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Lab", pipeline_response) + deserialized = self._deserialize("Lab", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized + return deserialized # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}"} # type: ignore - - def _claim_any_vm_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _claim_any_vm_initial(self, resource_group_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1142,37 +1078,41 @@ def _claim_any_vm_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_claim_any_vm_request( + _request = build_claim_any_vm_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._claim_any_vm_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _claim_any_vm_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/claimAnyVm"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_claim_any_vm(self, resource_group_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -1183,14 +1123,6 @@ def begin_claim_any_vm(self, resource_group_name: str, name: str, **kwargs: Any) :type resource_group_name: str :param name: The name of the lab. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1198,15 +1130,13 @@ def begin_claim_any_vm(self, resource_group_name: str, name: str, **kwargs: Any) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._claim_any_vm_initial( # type: ignore + raw_result = self._claim_any_vm_initial( resource_group_name=resource_group_name, name=name, api_version=api_version, @@ -1215,37 +1145,36 @@ def begin_claim_any_vm(self, resource_group_name: str, name: str, **kwargs: Any) params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_claim_any_vm.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/claimAnyVm"} # type: ignore - - def _create_environment_initial( # pylint: disable=inconsistent-return-statements + def _create_environment_initial( self, resource_group_name: str, name: str, - lab_virtual_machine_creation_parameter: Union[_models.LabVirtualMachineCreationParameter, IO], + lab_virtual_machine_creation_parameter: Union[_models.LabVirtualMachineCreationParameter, IO[bytes]], **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1256,21 +1185,19 @@ def _create_environment_initial( # pylint: disable=inconsistent-return-statemen _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(lab_virtual_machine_creation_parameter, (IO, bytes)): + if isinstance(lab_virtual_machine_creation_parameter, (IOBase, bytes)): _content = lab_virtual_machine_creation_parameter else: _json = self._serialize.body(lab_virtual_machine_creation_parameter, "LabVirtualMachineCreationParameter") - request = build_create_environment_request( + _request = build_create_environment_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, @@ -1278,27 +1205,33 @@ def _create_environment_initial( # pylint: disable=inconsistent-return-statemen content_type=content_type, json=_json, content=_content, - template_url=self._create_environment_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_environment_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/createEnvironment"} # type: ignore + return deserialized # type: ignore @overload def begin_create_environment( @@ -1323,14 +1256,6 @@ def begin_create_environment( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1341,7 +1266,7 @@ def begin_create_environment( self, resource_group_name: str, name: str, - lab_virtual_machine_creation_parameter: IO, + lab_virtual_machine_creation_parameter: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -1354,18 +1279,10 @@ def begin_create_environment( :type name: str :param lab_virtual_machine_creation_parameter: Properties for creating a virtual machine. Required. - :type lab_virtual_machine_creation_parameter: IO + :type lab_virtual_machine_creation_parameter: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1376,7 +1293,7 @@ def begin_create_environment( self, resource_group_name: str, name: str, - lab_virtual_machine_creation_parameter: Union[_models.LabVirtualMachineCreationParameter, IO], + lab_virtual_machine_creation_parameter: Union[_models.LabVirtualMachineCreationParameter, IO[bytes]], **kwargs: Any ) -> LROPoller[None]: """Create virtual machines in a lab. This operation can take a while to complete. @@ -1386,20 +1303,9 @@ def begin_create_environment( :param name: The name of the lab. Required. :type name: str :param lab_virtual_machine_creation_parameter: Properties for creating a virtual machine. Is - either a model type or a IO type. Required. + either a LabVirtualMachineCreationParameter type or a IO[bytes] type. Required. :type lab_virtual_machine_creation_parameter: - ~azure.mgmt.devtestlabs.models.LabVirtualMachineCreationParameter or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + ~azure.mgmt.devtestlabs.models.LabVirtualMachineCreationParameter or IO[bytes] :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1407,16 +1313,14 @@ def begin_create_environment( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_environment_initial( # type: ignore + raw_result = self._create_environment_initial( resource_group_name=resource_group_name, name=name, lab_virtual_machine_creation_parameter=lab_virtual_machine_creation_parameter, @@ -1427,38 +1331,37 @@ def begin_create_environment( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_create_environment.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/createEnvironment"} # type: ignore - - def _export_resource_usage_initial( # pylint: disable=inconsistent-return-statements + def _export_resource_usage_initial( self, resource_group_name: str, name: str, blob_storage_absolute_sas_uri: Optional[str] = None, usage_start_date: Optional[datetime.datetime] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1469,45 +1372,49 @@ def _export_resource_usage_initial( # pylint: disable=inconsistent-return-state _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) _export_resource_usage_parameters = _models.ExportResourceUsageParameters( blob_storage_absolute_sas_uri=blob_storage_absolute_sas_uri, usage_start_date=usage_start_date ) _json = self._serialize.body(_export_resource_usage_parameters, "ExportResourceUsageParameters") - request = build_export_resource_usage_request( + _request = build_export_resource_usage_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._export_resource_usage_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _export_resource_usage_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/exportResourceUsage"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_export_resource_usage( @@ -1531,14 +1438,6 @@ def begin_export_resource_usage( :param usage_start_date: The start time of the usage. If not provided, usage will be reported since the beginning of data collection. Default value is None. :type usage_start_date: ~datetime.datetime - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1546,16 +1445,14 @@ def begin_export_resource_usage( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._export_resource_usage_initial( # type: ignore + raw_result = self._export_resource_usage_initial( resource_group_name=resource_group_name, name=name, blob_storage_absolute_sas_uri=blob_storage_absolute_sas_uri, @@ -1567,28 +1464,27 @@ def begin_export_resource_usage( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_export_resource_usage.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/exportResourceUsage"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def generate_upload_uri( @@ -1602,12 +1498,11 @@ def generate_upload_uri( :type name: str :param blob_name: The blob name of the upload URI. Default value is None. :type blob_name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: GenerateUploadUriResponse or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.GenerateUploadUriResponse :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1618,31 +1513,28 @@ def generate_upload_uri( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.GenerateUploadUriResponse] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.GenerateUploadUriResponse] = kwargs.pop("cls", None) _generate_upload_uri_parameter = _models.GenerateUploadUriParameter(blob_name=blob_name) _json = self._serialize.body(_generate_upload_uri_parameter, "GenerateUploadUriParameter") - request = build_generate_upload_uri_request( + _request = build_generate_upload_uri_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self.generate_upload_uri.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1651,24 +1543,22 @@ def generate_upload_uri( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("GenerateUploadUriResponse", pipeline_response) + deserialized = self._deserialize("GenerateUploadUriResponse", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - generate_upload_uri.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/generateUploadUri"} # type: ignore + return deserialized # type: ignore - def _import_virtual_machine_initial( # pylint: disable=inconsistent-return-statements + def _import_virtual_machine_initial( self, resource_group_name: str, name: str, source_virtual_machine_resource_id: Optional[str] = None, destination_virtual_machine_name: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1679,11 +1569,9 @@ def _import_virtual_machine_initial( # pylint: disable=inconsistent-return-stat _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) _import_lab_virtual_machine_request = _models.ImportLabVirtualMachineRequest( destination_virtual_machine_name=destination_virtual_machine_name, @@ -1691,34 +1579,40 @@ def _import_virtual_machine_initial( # pylint: disable=inconsistent-return-stat ) _json = self._serialize.body(_import_lab_virtual_machine_request, "ImportLabVirtualMachineRequest") - request = build_import_virtual_machine_request( + _request = build_import_virtual_machine_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, content_type=content_type, json=_json, - template_url=self._import_virtual_machine_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _import_virtual_machine_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/importVirtualMachine"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_import_virtual_machine( @@ -1741,14 +1635,6 @@ def begin_import_virtual_machine( :param destination_virtual_machine_name: The name of the virtual machine in the destination lab. Default value is None. :type destination_virtual_machine_name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1756,16 +1642,14 @@ def begin_import_virtual_machine( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._import_virtual_machine_initial( # type: ignore + raw_result = self._import_virtual_machine_initial( resource_group_name=resource_group_name, name=name, source_virtual_machine_resource_id=source_virtual_machine_resource_id, @@ -1777,28 +1661,27 @@ def begin_import_virtual_machine( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_import_virtual_machine.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/importVirtualMachine"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def list_vhds(self, resource_group_name: str, name: str, **kwargs: Any) -> Iterable["_models.LabVhd"]: @@ -1808,7 +1691,6 @@ def list_vhds(self, resource_group_name: str, name: str, **kwargs: Any) -> Itera :type resource_group_name: str :param name: The name of the lab. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either LabVhd or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.LabVhd] :raises ~azure.core.exceptions.HttpResponseError: @@ -1816,12 +1698,10 @@ def list_vhds(self, resource_group_name: str, name: str, **kwargs: Any) -> Itera _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVhdList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabVhdList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1832,17 +1712,15 @@ def list_vhds(self, resource_group_name: str, name: str, **kwargs: Any) -> Itera def prepare_request(next_link=None): if not next_link: - request = build_list_vhds_request( + _request = build_list_vhds_request( resource_group_name=resource_group_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_vhds.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -1854,26 +1732,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("LabVhdList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1884,5 +1762,3 @@ def get_next(next_link=None): return pipeline_response return ItemPaged(get_next, extract_data) - - list_vhds.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/listVhds"} # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_notification_channels_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_notification_channels_operations.py index 9d291dd11db1..cb49661daf26 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_notification_channels_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_notification_channels_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Iterable, Optional, Type, TypeVar, Union, overload import urllib.parse from azure.core.exceptions import ( @@ -20,20 +21,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -55,7 +54,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -69,7 +68,7 @@ def build_list_request( "labName": _SERIALIZER.url("lab_name", lab_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -100,7 +99,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -115,7 +114,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -134,8 +133,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -150,7 +149,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -169,7 +168,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -184,7 +183,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -201,8 +200,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -217,7 +216,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -236,8 +235,8 @@ def build_notify_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -252,7 +251,7 @@ def build_notify_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -313,7 +312,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either NotificationChannel or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.NotificationChannel] :raises ~azure.core.exceptions.HttpResponseError: @@ -321,12 +319,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.NotificationChannelList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.NotificationChannelList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -337,7 +333,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -346,12 +342,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -363,26 +357,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("NotificationChannelList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -394,8 +388,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels"} # type: ignore - @distributed_trace def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -411,12 +403,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=webHookUrl)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -427,27 +418,24 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.NotificationChannel] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.NotificationChannel] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -456,14 +444,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("NotificationChannel", pipeline_response) + deserialized = self._deserialize("NotificationChannel", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}"} # type: ignore + return deserialized # type: ignore @overload def create_or_update( @@ -489,7 +475,6 @@ def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: @@ -501,7 +486,7 @@ def create_or_update( resource_group_name: str, lab_name: str, name: str, - notification_channel: IO, + notification_channel: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -515,11 +500,10 @@ def create_or_update( :param name: The name of the notification channel. Required. :type name: str :param notification_channel: A notification. Required. - :type notification_channel: IO + :type notification_channel: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: @@ -531,7 +515,7 @@ def create_or_update( resource_group_name: str, lab_name: str, name: str, - notification_channel: Union[_models.NotificationChannel, IO], + notification_channel: Union[_models.NotificationChannel, IO[bytes]], **kwargs: Any ) -> _models.NotificationChannel: """Create or replace an existing notification channel. @@ -542,17 +526,14 @@ def create_or_update( :type lab_name: str :param name: The name of the notification channel. Required. :type name: str - :param notification_channel: A notification. Is either a model type or a IO type. Required. - :type notification_channel: ~azure.mgmt.devtestlabs.models.NotificationChannel or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param notification_channel: A notification. Is either a NotificationChannel type or a + IO[bytes] type. Required. + :type notification_channel: ~azure.mgmt.devtestlabs.models.NotificationChannel or IO[bytes] :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -563,21 +544,19 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.NotificationChannel] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.NotificationChannel] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(notification_channel, (IO, bytes)): + if isinstance(notification_channel, (IOBase, bytes)): _content = notification_channel else: _json = self._serialize.body(notification_channel, "NotificationChannel") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -586,15 +565,14 @@ def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -603,18 +581,12 @@ def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("NotificationChannel", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("NotificationChannel", pipeline_response) + deserialized = self._deserialize("NotificationChannel", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -628,12 +600,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the notification channel. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -644,26 +615,23 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -673,9 +641,7 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace def update( @@ -691,12 +657,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: NotificationChannel or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.NotificationChannel :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -707,16 +672,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.NotificationChannel] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.NotificationChannel] = kwargs.pop("cls", None) _notification_channel = _models.NotificationChannelFragment(tags=tags) _json = self._serialize.body(_notification_channel, "NotificationChannelFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -724,15 +687,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -741,14 +703,12 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("NotificationChannel", pipeline_response) + deserialized = self._deserialize("NotificationChannel", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def notify( # pylint: disable=inconsistent-return-statements @@ -773,12 +733,11 @@ def notify( # pylint: disable=inconsistent-return-statements :type event_name: str or ~azure.mgmt.devtestlabs.models.NotificationChannelEventType :param json_payload: Properties for the notification in json format. Default value is None. :type json_payload: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -789,16 +748,14 @@ def notify( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) _notify_parameters = _models.NotifyParameters(event_name=event_name, json_payload=json_payload) _json = self._serialize.body(_notify_parameters, "NotifyParameters") - request = build_notify_request( + _request = build_notify_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -806,15 +763,14 @@ def notify( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self.notify.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -824,6 +780,4 @@ def notify( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - notify.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}/notify"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_operations.py index e229fd00656c..6162f1682584 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, Callable, Dict, Optional, TypeVar +from typing import Any, Callable, Dict, Optional, Type, TypeVar from azure.core.exceptions import ( ClientAuthenticationError, @@ -18,20 +18,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -43,7 +41,7 @@ def build_get_request(location_name: str, name: str, subscription_id: str, **kwa _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -57,7 +55,7 @@ def build_get_request(location_name: str, name: str, subscription_id: str, **kwa "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -95,12 +93,11 @@ def get(self, location_name: str, name: str, **kwargs: Any) -> _models.Operation :type location_name: str :param name: The name of the operation. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: OperationResult or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.OperationResult :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -111,25 +108,22 @@ def get(self, location_name: str, name: str, **kwargs: Any) -> _models.Operation _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.OperationResult] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.OperationResult] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( location_name=location_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -138,15 +132,9 @@ def get(self, location_name: str, name: str, **kwargs: Any) -> _models.Operation map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("OperationResult", pipeline_response) - - if response.status_code == 202: - deserialized = self._deserialize("OperationResult", pipeline_response) + deserialized = self._deserialize("OperationResult", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.DevTestLab/locations/{locationName}/operations/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_policies_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_policies_operations.py index c3a9b7da55e3..3ee487b88d73 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_policies_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_policies_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Iterable, Optional, Type, TypeVar, Union, overload import urllib.parse from azure.core.exceptions import ( @@ -20,20 +21,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -56,7 +55,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -71,7 +70,7 @@ def build_list_request( "policySetName": _SERIALIZER.url("policy_set_name", policy_set_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -103,7 +102,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -119,7 +118,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -138,8 +137,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -155,7 +154,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -174,7 +173,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -190,7 +189,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -207,8 +206,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -224,7 +223,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -288,7 +287,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Policy or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Policy] :raises ~azure.core.exceptions.HttpResponseError: @@ -296,12 +294,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.PolicyList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.PolicyList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -312,7 +308,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, @@ -322,12 +318,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -339,26 +333,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("PolicyList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -370,8 +364,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies"} # type: ignore - @distributed_trace def get( self, @@ -395,12 +387,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=description)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -411,12 +402,10 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Policy] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Policy] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, @@ -424,15 +413,14 @@ def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -441,14 +429,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Policy", pipeline_response) + deserialized = self._deserialize("Policy", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}"} # type: ignore + return deserialized # type: ignore @overload def create_or_update( @@ -477,7 +463,6 @@ def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: @@ -490,7 +475,7 @@ def create_or_update( lab_name: str, policy_set_name: str, name: str, - policy: IO, + policy: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -506,11 +491,10 @@ def create_or_update( :param name: The name of the policy. Required. :type name: str :param policy: A Policy. Required. - :type policy: IO + :type policy: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: @@ -523,7 +507,7 @@ def create_or_update( lab_name: str, policy_set_name: str, name: str, - policy: Union[_models.Policy, IO], + policy: Union[_models.Policy, IO[bytes]], **kwargs: Any ) -> _models.Policy: """Create or replace an existing policy. @@ -536,17 +520,13 @@ def create_or_update( :type policy_set_name: str :param name: The name of the policy. Required. :type name: str - :param policy: A Policy. Is either a model type or a IO type. Required. - :type policy: ~azure.mgmt.devtestlabs.models.Policy or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param policy: A Policy. Is either a Policy type or a IO[bytes] type. Required. + :type policy: ~azure.mgmt.devtestlabs.models.Policy or IO[bytes] :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -557,21 +537,19 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Policy] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Policy] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(policy, (IO, bytes)): + if isinstance(policy, (IOBase, bytes)): _content = policy else: _json = self._serialize.body(policy, "Policy") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, @@ -581,15 +559,14 @@ def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -598,18 +575,12 @@ def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Policy", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Policy", pipeline_response) + deserialized = self._deserialize("Policy", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -625,12 +596,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type policy_set_name: str :param name: The name of the policy. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -641,27 +611,24 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -671,9 +638,7 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace def update( @@ -697,12 +662,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Policy or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Policy :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -713,16 +677,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Policy] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Policy] = kwargs.pop("cls", None) _policy = _models.PolicyFragment(tags=tags) _json = self._serialize.body(_policy, "PolicyFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, policy_set_name=policy_set_name, @@ -731,15 +693,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -748,11 +709,9 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Policy", pipeline_response) + deserialized = self._deserialize("Policy", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{policySetName}/policies/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_policy_sets_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_policy_sets_operations.py index 93c6206b4e64..956d2988b740 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_policy_sets_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_policy_sets_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar +from typing import Any, Callable, Dict, List, Optional, Type, TypeVar from azure.core.exceptions import ( ClientAuthenticationError, @@ -18,20 +18,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -45,8 +43,8 @@ def build_evaluate_policies_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -61,7 +59,7 @@ def build_evaluate_policies_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -112,12 +110,11 @@ def evaluate_policies( :type name: str :param policies: Policies to evaluate. Default value is None. :type policies: list[~azure.mgmt.devtestlabs.models.EvaluatePoliciesProperties] - :keyword callable cls: A custom type or function that will be passed the direct response :return: EvaluatePoliciesResponse or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.EvaluatePoliciesResponse :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -128,16 +125,14 @@ def evaluate_policies( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.EvaluatePoliciesResponse] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.EvaluatePoliciesResponse] = kwargs.pop("cls", None) _evaluate_policies_request = _models.EvaluatePoliciesRequest(policies=policies) _json = self._serialize.body(_evaluate_policies_request, "EvaluatePoliciesRequest") - request = build_evaluate_policies_request( + _request = build_evaluate_policies_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -145,15 +140,14 @@ def evaluate_policies( api_version=api_version, content_type=content_type, json=_json, - template_url=self.evaluate_policies.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -162,11 +156,9 @@ def evaluate_policies( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("EvaluatePoliciesResponse", pipeline_response) + deserialized = self._deserialize("EvaluatePoliciesResponse", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - evaluate_policies.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/policysets/{name}/evaluatePolicies"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_provider_operations_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_provider_operations_operations.py index 0db3468d3906..ec67645717a4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_provider_operations_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_provider_operations_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- import sys -from typing import Any, Callable, Dict, Iterable, Optional, TypeVar +from typing import Any, Callable, Dict, Iterable, Optional, Type, TypeVar import urllib.parse from azure.core.exceptions import ( @@ -20,20 +20,18 @@ ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -45,7 +43,7 @@ def build_list_request(**kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -83,7 +81,6 @@ def __init__(self, *args, **kwargs): def list(self, **kwargs: Any) -> Iterable["_models.OperationMetadata"]: """Result of the request to list REST API operations. - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either OperationMetadata or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.OperationMetadata] :raises ~azure.core.exceptions.HttpResponseError: @@ -91,12 +88,10 @@ def list(self, **kwargs: Any) -> Iterable["_models.OperationMetadata"]: _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ProviderOperationResult] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ProviderOperationResult] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -107,14 +102,12 @@ def list(self, **kwargs: Any) -> Iterable["_models.OperationMetadata"]: def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -126,26 +119,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ProviderOperationResult", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -156,5 +149,3 @@ def get_next(next_link=None): return pipeline_response return ItemPaged(get_next, extract_data) - - list.metadata = {"url": "/providers/Microsoft.DevTestLab/operations"} # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_schedules_operations.py index ebfa6b9636a1..ec072c87a927 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_schedules_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_schedules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -57,7 +58,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -71,7 +72,7 @@ def build_list_request( "labName": _SERIALIZER.url("lab_name", lab_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -102,7 +103,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -117,7 +118,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -136,8 +137,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -152,7 +153,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -171,7 +172,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -186,7 +187,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -203,8 +204,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -219,7 +220,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -238,7 +239,7 @@ def build_execute_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -253,7 +254,7 @@ def build_execute_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -270,7 +271,7 @@ def build_list_applicable_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -285,7 +286,7 @@ def build_list_applicable_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -344,7 +345,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -352,12 +352,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -368,7 +366,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -377,12 +375,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -394,26 +390,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -425,8 +421,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules"} # type: ignore - @distributed_trace def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -442,12 +436,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=status)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -458,27 +451,24 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -487,14 +477,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @overload def create_or_update( @@ -520,7 +508,6 @@ def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -532,7 +519,7 @@ def create_or_update( resource_group_name: str, lab_name: str, name: str, - schedule: IO, + schedule: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -546,11 +533,10 @@ def create_or_update( :param name: The name of the schedule. Required. :type name: str :param schedule: A schedule. Required. - :type schedule: IO + :type schedule: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -558,7 +544,12 @@ def create_or_update( @distributed_trace def create_or_update( - self, resource_group_name: str, lab_name: str, name: str, schedule: Union[_models.Schedule, IO], **kwargs: Any + self, + resource_group_name: str, + lab_name: str, + name: str, + schedule: Union[_models.Schedule, IO[bytes]], + **kwargs: Any ) -> _models.Schedule: """Create or replace an existing schedule. @@ -568,17 +559,13 @@ def create_or_update( :type lab_name: str :param name: The name of the schedule. Required. :type name: str - :param schedule: A schedule. Is either a model type or a IO type. Required. - :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param schedule: A schedule. Is either a Schedule type or a IO[bytes] type. Required. + :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO[bytes] :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -589,21 +576,19 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(schedule, (IO, bytes)): + if isinstance(schedule, (IOBase, bytes)): _content = schedule else: _json = self._serialize.body(schedule, "Schedule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -612,15 +597,14 @@ def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -629,18 +613,12 @@ def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Schedule", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -654,12 +632,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -670,26 +647,23 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -699,9 +673,7 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace def update( @@ -717,12 +689,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -733,16 +704,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) _schedule = _models.ScheduleFragment(tags=tags) _json = self._serialize.body(_schedule, "ScheduleFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -750,15 +719,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -767,19 +735,15 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized + return deserialized # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}"} # type: ignore - - def _execute_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _execute_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -790,38 +754,42 @@ def _execute_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_execute_request( + _request = build_execute_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._execute_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _execute_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}/execute"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_execute(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -833,14 +801,6 @@ def begin_execute(self, resource_group_name: str, lab_name: str, name: str, **kw :type lab_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -848,15 +808,13 @@ def begin_execute(self, resource_group_name: str, lab_name: str, name: str, **kw _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._execute_initial( # type: ignore + raw_result = self._execute_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -866,28 +824,27 @@ def begin_execute(self, resource_group_name: str, lab_name: str, name: str, **kw params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_execute.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}/execute"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def list_applicable( @@ -901,7 +858,6 @@ def list_applicable( :type lab_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -909,12 +865,10 @@ def list_applicable( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -925,18 +879,16 @@ def list_applicable( def prepare_request(next_link=None): if not next_link: - request = build_list_applicable_request( + _request = build_list_applicable_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_applicable.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -948,26 +900,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -978,5 +930,3 @@ def get_next(next_link=None): return pipeline_response return ItemPaged(get_next, extract_data) - - list_applicable.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/schedules/{name}/listApplicable"} # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_secrets_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_secrets_operations.py index e5a1dfd67fed..3eb5d0ba7c17 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_secrets_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_secrets_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -58,7 +59,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -73,7 +74,7 @@ def build_list_request( "userName": _SERIALIZER.url("user_name", user_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -105,7 +106,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -121,7 +122,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -140,8 +141,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -157,7 +158,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -176,7 +177,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -192,7 +193,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -209,8 +210,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -226,7 +227,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -290,7 +291,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Secret or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Secret] :raises ~azure.core.exceptions.HttpResponseError: @@ -298,12 +298,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.SecretList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.SecretList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -314,7 +312,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -324,12 +322,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -341,26 +337,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("SecretList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -372,8 +368,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets"} # type: ignore - @distributed_trace def get( self, @@ -397,12 +391,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=value)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Secret or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Secret :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -413,12 +406,10 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Secret] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Secret] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -426,15 +417,14 @@ def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -443,14 +433,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Secret", pipeline_response) + deserialized = self._deserialize("Secret", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( self, @@ -458,10 +446,10 @@ def _create_or_update_initial( lab_name: str, user_name: str, name: str, - secret: Union[_models.Secret, IO], + secret: Union[_models.Secret, IO[bytes]], **kwargs: Any - ) -> _models.Secret: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -472,21 +460,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Secret] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(secret, (IO, bytes)): + if isinstance(secret, (IOBase, bytes)): _content = secret else: _json = self._serialize.body(secret, "Secret") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -496,35 +482,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Secret", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Secret", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -553,14 +537,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Secret or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Secret] :raises ~azure.core.exceptions.HttpResponseError: @@ -573,7 +549,7 @@ def begin_create_or_update( lab_name: str, user_name: str, name: str, - secret: IO, + secret: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -589,18 +565,10 @@ def begin_create_or_update( :param name: The name of the secret. Required. :type name: str :param secret: A secret. Required. - :type secret: IO + :type secret: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either Secret or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Secret] :raises ~azure.core.exceptions.HttpResponseError: @@ -613,7 +581,7 @@ def begin_create_or_update( lab_name: str, user_name: str, name: str, - secret: Union[_models.Secret, IO], + secret: Union[_models.Secret, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.Secret]: """Create or replace an existing secret. This operation can take a while to complete. @@ -626,19 +594,8 @@ def begin_create_or_update( :type user_name: str :param name: The name of the secret. Required. :type name: str - :param secret: A secret. Is either a model type or a IO type. Required. - :type secret: ~azure.mgmt.devtestlabs.models.Secret or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param secret: A secret. Is either a Secret type or a IO[bytes] type. Required. + :type secret: ~azure.mgmt.devtestlabs.models.Secret or IO[bytes] :return: An instance of LROPoller that returns either Secret or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.Secret] :raises ~azure.core.exceptions.HttpResponseError: @@ -646,16 +603,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Secret] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Secret] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -668,30 +623,31 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("Secret", pipeline_response) + deserialized = self._deserialize("Secret", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.Secret].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return LROPoller[_models.Secret]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -707,12 +663,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type user_name: str :param name: The name of the secret. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -723,27 +678,24 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -753,9 +705,7 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace def update( @@ -779,12 +729,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Secret or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Secret :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -795,16 +744,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Secret] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Secret] = kwargs.pop("cls", None) _secret = _models.SecretFragment(tags=tags) _json = self._serialize.body(_secret, "SecretFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -813,15 +760,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -830,11 +776,9 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Secret", pipeline_response) + deserialized = self._deserialize("Secret", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/secrets/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_fabric_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_fabric_schedules_operations.py index fe7a114806d0..93d7e7a38cef 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_fabric_schedules_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_fabric_schedules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -59,7 +60,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -75,7 +76,7 @@ def build_list_request( "serviceFabricName": _SERIALIZER.url("service_fabric_name", service_fabric_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -108,7 +109,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -125,7 +126,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -150,8 +151,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -168,7 +169,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -193,7 +194,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -210,7 +211,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -233,8 +234,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -251,7 +252,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -276,7 +277,7 @@ def build_execute_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -293,7 +294,7 @@ def build_execute_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -358,7 +359,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -366,12 +366,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -382,7 +380,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -393,12 +391,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -410,26 +406,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -441,8 +437,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules"} # type: ignore - @distributed_trace def get( self, @@ -469,12 +463,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=status)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -485,12 +478,10 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -499,15 +490,14 @@ def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -516,14 +506,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @overload def create_or_update( @@ -555,7 +543,6 @@ def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -569,7 +556,7 @@ def create_or_update( user_name: str, service_fabric_name: str, name: str, - schedule: IO, + schedule: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -587,11 +574,10 @@ def create_or_update( :param name: The name of the schedule. Required. :type name: str :param schedule: A schedule. Required. - :type schedule: IO + :type schedule: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -605,7 +591,7 @@ def create_or_update( user_name: str, service_fabric_name: str, name: str, - schedule: Union[_models.Schedule, IO], + schedule: Union[_models.Schedule, IO[bytes]], **kwargs: Any ) -> _models.Schedule: """Create or replace an existing schedule. @@ -620,17 +606,13 @@ def create_or_update( :type service_fabric_name: str :param name: The name of the schedule. Required. :type name: str - :param schedule: A schedule. Is either a model type or a IO type. Required. - :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param schedule: A schedule. Is either a Schedule type or a IO[bytes] type. Required. + :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO[bytes] :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -641,21 +623,19 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(schedule, (IO, bytes)): + if isinstance(schedule, (IOBase, bytes)): _content = schedule else: _json = self._serialize.body(schedule, "Schedule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -666,15 +646,14 @@ def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -683,18 +662,12 @@ def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Schedule", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -718,12 +691,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type service_fabric_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -734,12 +706,10 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -747,15 +717,14 @@ def delete( # pylint: disable=inconsistent-return-statements name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -765,9 +734,7 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace def update( @@ -794,12 +761,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -810,16 +776,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) _schedule = _models.ScheduleFragment(tags=tags) _json = self._serialize.body(_schedule, "ScheduleFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -829,15 +793,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -846,16 +809,14 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore - def _execute_initial( # pylint: disable=inconsistent-return-statements + def _execute_initial( self, resource_group_name: str, lab_name: str, @@ -863,8 +824,8 @@ def _execute_initial( # pylint: disable=inconsistent-return-statements service_fabric_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -875,12 +836,10 @@ def _execute_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_execute_request( + _request = build_execute_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -888,27 +847,33 @@ def _execute_initial( # pylint: disable=inconsistent-return-statements name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._execute_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _execute_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}/execute"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_execute( @@ -932,14 +897,6 @@ def begin_execute( :type service_fabric_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -947,15 +904,13 @@ def begin_execute( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._execute_initial( # type: ignore + raw_result = self._execute_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -967,25 +922,24 @@ def begin_execute( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_execute.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{serviceFabricName}/schedules/{name}/execute"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_fabrics_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_fabrics_operations.py index 888b5d82df14..4719448bbcc1 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_fabrics_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_fabrics_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -58,7 +59,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -73,7 +74,7 @@ def build_list_request( "userName": _SERIALIZER.url("user_name", user_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -105,7 +106,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -121,7 +122,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -140,8 +141,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -157,7 +158,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -176,7 +177,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -192,7 +193,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -209,8 +210,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -226,7 +227,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -245,7 +246,7 @@ def build_list_applicable_schedules_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -261,7 +262,7 @@ def build_list_applicable_schedules_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -278,7 +279,7 @@ def build_start_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -294,7 +295,7 @@ def build_start_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -311,7 +312,7 @@ def build_stop_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -327,7 +328,7 @@ def build_stop_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -389,7 +390,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either ServiceFabric or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.ServiceFabric] :raises ~azure.core.exceptions.HttpResponseError: @@ -397,12 +397,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabricList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ServiceFabricList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -413,7 +411,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -423,12 +421,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -440,26 +436,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ServiceFabricList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -471,8 +467,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics"} # type: ignore - @distributed_trace def get( self, @@ -496,12 +490,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($expand=applicableSchedule)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceFabric or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceFabric :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -512,12 +505,10 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabric] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ServiceFabric] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -525,15 +516,14 @@ def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -542,14 +532,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServiceFabric", pipeline_response) + deserialized = self._deserialize("ServiceFabric", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( self, @@ -557,10 +545,10 @@ def _create_or_update_initial( lab_name: str, user_name: str, name: str, - service_fabric: Union[_models.ServiceFabric, IO], + service_fabric: Union[_models.ServiceFabric, IO[bytes]], **kwargs: Any - ) -> _models.ServiceFabric: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -571,21 +559,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabric] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(service_fabric, (IO, bytes)): + if isinstance(service_fabric, (IOBase, bytes)): _content = service_fabric else: _json = self._serialize.body(service_fabric, "ServiceFabric") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -595,35 +581,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("ServiceFabric", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("ServiceFabric", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -652,14 +636,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either ServiceFabric or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.ServiceFabric] @@ -673,7 +649,7 @@ def begin_create_or_update( lab_name: str, user_name: str, name: str, - service_fabric: IO, + service_fabric: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -689,18 +665,10 @@ def begin_create_or_update( :param name: The name of the service fabric. Required. :type name: str :param service_fabric: A Service Fabric. Required. - :type service_fabric: IO + :type service_fabric: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either ServiceFabric or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.ServiceFabric] @@ -714,7 +682,7 @@ def begin_create_or_update( lab_name: str, user_name: str, name: str, - service_fabric: Union[_models.ServiceFabric, IO], + service_fabric: Union[_models.ServiceFabric, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.ServiceFabric]: """Create or replace an existing service fabric. This operation can take a while to complete. @@ -727,19 +695,9 @@ def begin_create_or_update( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :param service_fabric: A Service Fabric. Is either a model type or a IO type. Required. - :type service_fabric: ~azure.mgmt.devtestlabs.models.ServiceFabric or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param service_fabric: A Service Fabric. Is either a ServiceFabric type or a IO[bytes] type. + Required. + :type service_fabric: ~azure.mgmt.devtestlabs.models.ServiceFabric or IO[bytes] :return: An instance of LROPoller that returns either ServiceFabric or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.ServiceFabric] @@ -748,16 +706,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabric] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.ServiceFabric] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -770,35 +726,36 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("ServiceFabric", pipeline_response) + deserialized = self._deserialize("ServiceFabric", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.ServiceFabric].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return LROPoller[_models.ServiceFabric]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements + def _delete_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -809,39 +766,43 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_delete( @@ -857,14 +818,6 @@ def begin_delete( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -872,15 +825,13 @@ def begin_delete( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -891,28 +842,27 @@ def begin_delete( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def update( @@ -936,12 +886,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceFabric or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceFabric :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -952,16 +901,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceFabric] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.ServiceFabric] = kwargs.pop("cls", None) _service_fabric = _models.ServiceFabricFragment(tags=tags) _json = self._serialize.body(_service_fabric, "ServiceFabricFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -970,15 +917,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -987,14 +933,12 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServiceFabric", pipeline_response) + deserialized = self._deserialize("ServiceFabric", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def list_applicable_schedules( @@ -1010,12 +954,11 @@ def list_applicable_schedules( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ApplicableSchedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ApplicableSchedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1026,27 +969,24 @@ def list_applicable_schedules( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ApplicableSchedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ApplicableSchedule] = kwargs.pop("cls", None) - request = build_list_applicable_schedules_request( + _request = build_list_applicable_schedules_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_applicable_schedules.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1055,19 +995,17 @@ def list_applicable_schedules( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ApplicableSchedule", pipeline_response) + deserialized = self._deserialize("ApplicableSchedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - list_applicable_schedules.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/listApplicableSchedules"} # type: ignore + return deserialized # type: ignore - def _start_initial( # pylint: disable=inconsistent-return-statements + def _start_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1078,39 +1016,43 @@ def _start_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_start_request( + _request = build_start_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._start_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _start_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/start"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_start( @@ -1126,14 +1068,6 @@ def begin_start( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1141,15 +1075,13 @@ def begin_start( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._start_initial( # type: ignore + raw_result = self._start_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -1160,33 +1092,32 @@ def begin_start( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_start.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/start"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _stop_initial( # pylint: disable=inconsistent-return-statements + def _stop_initial( self, resource_group_name: str, lab_name: str, user_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1197,39 +1128,43 @@ def _stop_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_stop_request( + _request = build_stop_request( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._stop_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _stop_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/stop"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_stop( @@ -1245,14 +1180,6 @@ def begin_stop( :type user_name: str :param name: The name of the service fabric. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1260,15 +1187,13 @@ def begin_stop( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._stop_initial( # type: ignore + raw_result = self._stop_initial( resource_group_name=resource_group_name, lab_name=lab_name, user_name=user_name, @@ -1279,25 +1204,24 @@ def begin_stop( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_stop.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/servicefabrics/{name}/stop"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_runners_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_runners_operations.py index 1f9e6eeb337e..935bbd090fcb 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_runners_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_service_runners_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Optional, Type, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -18,20 +19,18 @@ map_error, ) from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -45,7 +44,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -60,7 +59,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -77,8 +76,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -93,7 +92,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -112,7 +111,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -127,7 +126,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -167,12 +166,11 @@ def get(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) :type lab_name: str :param name: The name of the service runner. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceRunner or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceRunner :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -183,26 +181,23 @@ def get(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceRunner] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ServiceRunner] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -211,14 +206,12 @@ def get(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ServiceRunner", pipeline_response) + deserialized = self._deserialize("ServiceRunner", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/servicerunners/{name}"} # type: ignore + return deserialized # type: ignore @overload def create_or_update( @@ -245,7 +238,6 @@ def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceRunner or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceRunner :raises ~azure.core.exceptions.HttpResponseError: @@ -257,7 +249,7 @@ def create_or_update( resource_group_name: str, lab_name: str, name: str, - service_runner: IO, + service_runner: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -272,11 +264,10 @@ def create_or_update( :type name: str :param service_runner: A container for a managed identity to execute DevTest lab services. Required. - :type service_runner: IO + :type service_runner: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ServiceRunner or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceRunner :raises ~azure.core.exceptions.HttpResponseError: @@ -288,7 +279,7 @@ def create_or_update( resource_group_name: str, lab_name: str, name: str, - service_runner: Union[_models.ServiceRunner, IO], + service_runner: Union[_models.ServiceRunner, IO[bytes]], **kwargs: Any ) -> _models.ServiceRunner: """Create or replace an existing service runner. @@ -300,17 +291,13 @@ def create_or_update( :param name: The name of the service runner. Required. :type name: str :param service_runner: A container for a managed identity to execute DevTest lab services. Is - either a model type or a IO type. Required. - :type service_runner: ~azure.mgmt.devtestlabs.models.ServiceRunner or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + either a ServiceRunner type or a IO[bytes] type. Required. + :type service_runner: ~azure.mgmt.devtestlabs.models.ServiceRunner or IO[bytes] :return: ServiceRunner or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ServiceRunner :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -321,21 +308,19 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ServiceRunner] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.ServiceRunner] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(service_runner, (IO, bytes)): + if isinstance(service_runner, (IOBase, bytes)): _content = service_runner else: _json = self._serialize.body(service_runner, "ServiceRunner") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -344,15 +329,14 @@ def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -361,18 +345,12 @@ def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("ServiceRunner", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("ServiceRunner", pipeline_response) + deserialized = self._deserialize("ServiceRunner", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized - - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/servicerunners/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -386,12 +364,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type lab_name: str :param name: The name of the service runner. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -402,26 +379,23 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -431,6 +405,4 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/servicerunners/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_users_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_users_operations.py index 8b8b6e66f360..81e6c0ca863c 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_users_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_users_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -57,7 +58,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -71,7 +72,7 @@ def build_list_request( "labName": _SERIALIZER.url("lab_name", lab_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -102,7 +103,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -117,7 +118,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -136,8 +137,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -152,7 +153,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -171,7 +172,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -186,7 +187,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -203,8 +204,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -219,7 +220,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -280,7 +281,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either User or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.User] :raises ~azure.core.exceptions.HttpResponseError: @@ -288,12 +288,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.UserList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.UserList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -304,7 +302,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -313,12 +311,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -330,26 +326,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("UserList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -361,8 +357,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users"} # type: ignore - @distributed_trace def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -378,12 +372,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=identity)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: User or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.User :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -394,27 +387,24 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.User] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.User] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -423,19 +413,17 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("User", pipeline_response) + deserialized = self._deserialize("User", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( - self, resource_group_name: str, lab_name: str, name: str, user: Union[_models.User, IO], **kwargs: Any - ) -> _models.User: - error_map = { + self, resource_group_name: str, lab_name: str, name: str, user: Union[_models.User, IO[bytes]], **kwargs: Any + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -446,21 +434,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.User] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(user, (IO, bytes)): + if isinstance(user, (IOBase, bytes)): _content = user else: _json = self._serialize.body(user, "User") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -469,35 +455,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("User", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("User", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -523,14 +507,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either User or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.User] :raises ~azure.core.exceptions.HttpResponseError: @@ -542,7 +518,7 @@ def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - user: IO, + user: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -556,18 +532,10 @@ def begin_create_or_update( :param name: The name of the user profile. Required. :type name: str :param user: Profile of a lab user. Required. - :type user: IO + :type user: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either User or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.User] :raises ~azure.core.exceptions.HttpResponseError: @@ -575,7 +543,7 @@ def begin_create_or_update( @distributed_trace def begin_create_or_update( - self, resource_group_name: str, lab_name: str, name: str, user: Union[_models.User, IO], **kwargs: Any + self, resource_group_name: str, lab_name: str, name: str, user: Union[_models.User, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.User]: """Create or replace an existing user profile. This operation can take a while to complete. @@ -585,19 +553,8 @@ def begin_create_or_update( :type lab_name: str :param name: The name of the user profile. Required. :type name: str - :param user: Profile of a lab user. Is either a model type or a IO type. Required. - :type user: ~azure.mgmt.devtestlabs.models.User or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param user: Profile of a lab user. Is either a User type or a IO[bytes] type. Required. + :type user: ~azure.mgmt.devtestlabs.models.User or IO[bytes] :return: An instance of LROPoller that returns either User or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.User] :raises ~azure.core.exceptions.HttpResponseError: @@ -605,16 +562,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.User] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.User] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -626,35 +581,34 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("User", pipeline_response) + deserialized = self._deserialize("User", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.User].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return LROPoller[_models.User]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _delete_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -665,38 +619,42 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -708,14 +666,6 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa :type lab_name: str :param name: The name of the user profile. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -723,15 +673,13 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -741,28 +689,27 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def update( @@ -778,12 +725,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: User or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.User :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -794,16 +740,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.User] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.User] = kwargs.pop("cls", None) _user = _models.UserFragment(tags=tags) _json = self._serialize.body(_user, "UserFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -811,15 +755,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -828,11 +771,9 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("User", pipeline_response) + deserialized = self._deserialize("User", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_machine_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_machine_schedules_operations.py index 4bdf99893f48..dd25d3ef4b65 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_machine_schedules_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_machine_schedules_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -58,7 +59,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -73,7 +74,7 @@ def build_list_request( "virtualMachineName": _SERIALIZER.url("virtual_machine_name", virtual_machine_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -105,7 +106,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -121,7 +122,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -140,8 +141,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -157,7 +158,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -176,7 +177,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -192,7 +193,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -209,8 +210,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -226,7 +227,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -245,7 +246,7 @@ def build_execute_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -261,7 +262,7 @@ def build_execute_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -323,7 +324,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either Schedule or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.Schedule] :raises ~azure.core.exceptions.HttpResponseError: @@ -331,12 +331,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ScheduleList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ScheduleList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -347,7 +345,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -357,12 +355,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -374,26 +370,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("ScheduleList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -405,8 +401,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules"} # type: ignore - @distributed_trace def get( self, @@ -430,12 +424,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($select=status)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -446,12 +439,10 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -459,15 +450,14 @@ def get( subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -476,14 +466,12 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @overload def create_or_update( @@ -512,7 +500,6 @@ def create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -525,7 +512,7 @@ def create_or_update( lab_name: str, virtual_machine_name: str, name: str, - schedule: IO, + schedule: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -541,11 +528,10 @@ def create_or_update( :param name: The name of the schedule. Required. :type name: str :param schedule: A schedule. Required. - :type schedule: IO + :type schedule: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: @@ -558,7 +544,7 @@ def create_or_update( lab_name: str, virtual_machine_name: str, name: str, - schedule: Union[_models.Schedule, IO], + schedule: Union[_models.Schedule, IO[bytes]], **kwargs: Any ) -> _models.Schedule: """Create or replace an existing schedule. @@ -571,17 +557,13 @@ def create_or_update( :type virtual_machine_name: str :param name: The name of the schedule. Required. :type name: str - :param schedule: A schedule. Is either a model type or a IO type. Required. - :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response + :param schedule: A schedule. Is either a Schedule type or a IO[bytes] type. Required. + :type schedule: ~azure.mgmt.devtestlabs.models.Schedule or IO[bytes] :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -592,21 +574,19 @@ def create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(schedule, (IO, bytes)): + if isinstance(schedule, (IOBase, bytes)): _content = schedule else: _json = self._serialize.body(schedule, "Schedule") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -616,15 +596,14 @@ def create_or_update( content_type=content_type, json=_json, content=_content, - template_url=self.create_or_update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -633,18 +612,12 @@ def create_or_update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("Schedule", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def delete( # pylint: disable=inconsistent-return-statements @@ -660,12 +633,11 @@ def delete( # pylint: disable=inconsistent-return-statements :type virtual_machine_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: None or the result of cls(response) :rtype: None :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -676,27 +648,24 @@ def delete( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.delete.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -706,9 +675,7 @@ def delete( # pylint: disable=inconsistent-return-statements raise HttpResponseError(response=response, error_format=ARMErrorFormat) if cls: - return cls(pipeline_response, None, {}) - - delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}"} # type: ignore + return cls(pipeline_response, None, {}) # type: ignore @distributed_trace def update( @@ -732,12 +699,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: Schedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.Schedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -748,16 +714,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.Schedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.Schedule] = kwargs.pop("cls", None) _schedule = _models.ScheduleFragment(tags=tags) _json = self._serialize.body(_schedule, "ScheduleFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -766,15 +730,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -783,19 +746,17 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("Schedule", pipeline_response) + deserialized = self._deserialize("Schedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}"} # type: ignore + return deserialized # type: ignore - def _execute_initial( # pylint: disable=inconsistent-return-statements + def _execute_initial( self, resource_group_name: str, lab_name: str, virtual_machine_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -806,39 +767,43 @@ def _execute_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_execute_request( + _request = build_execute_request( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._execute_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _execute_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}/execute"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_execute( @@ -854,14 +819,6 @@ def begin_execute( :type virtual_machine_name: str :param name: The name of the schedule. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -869,15 +826,13 @@ def begin_execute( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._execute_initial( # type: ignore + raw_result = self._execute_initial( resource_group_name=resource_group_name, lab_name=lab_name, virtual_machine_name=virtual_machine_name, @@ -888,25 +843,24 @@ def begin_execute( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_execute.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{virtualMachineName}/schedules/{name}/execute"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_machines_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_machines_operations.py index 88cf34480260..ba14a7b96672 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_machines_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_machines_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, List, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, List, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -57,7 +58,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -71,7 +72,7 @@ def build_list_request( "labName": _SERIALIZER.url("lab_name", lab_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -102,7 +103,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -117,7 +118,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -136,8 +137,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -152,7 +153,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -171,7 +172,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -186,7 +187,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -203,8 +204,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -219,7 +220,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -238,8 +239,8 @@ def build_add_data_disk_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -254,7 +255,7 @@ def build_add_data_disk_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -273,8 +274,8 @@ def build_apply_artifacts_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -289,7 +290,7 @@ def build_apply_artifacts_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -308,7 +309,7 @@ def build_claim_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -323,7 +324,7 @@ def build_claim_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -340,8 +341,8 @@ def build_detach_data_disk_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -356,7 +357,7 @@ def build_detach_data_disk_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -375,7 +376,7 @@ def build_get_rdp_file_contents_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -390,7 +391,7 @@ def build_get_rdp_file_contents_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -407,7 +408,7 @@ def build_list_applicable_schedules_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -422,7 +423,7 @@ def build_list_applicable_schedules_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -439,7 +440,7 @@ def build_redeploy_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -454,7 +455,7 @@ def build_redeploy_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -471,8 +472,8 @@ def build_resize_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -487,7 +488,7 @@ def build_resize_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -506,7 +507,7 @@ def build_restart_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -521,7 +522,7 @@ def build_restart_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -538,7 +539,7 @@ def build_start_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -553,7 +554,7 @@ def build_start_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -570,7 +571,7 @@ def build_stop_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -585,7 +586,7 @@ def build_stop_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -602,7 +603,7 @@ def build_transfer_disks_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -617,7 +618,7 @@ def build_transfer_disks_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -634,7 +635,7 @@ def build_un_claim_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -649,7 +650,7 @@ def build_un_claim_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -709,7 +710,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either LabVirtualMachine or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.LabVirtualMachine] :raises ~azure.core.exceptions.HttpResponseError: @@ -717,12 +717,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachineList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabVirtualMachineList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -733,7 +731,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -742,12 +740,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -759,26 +755,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("LabVirtualMachineList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -790,8 +786,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines"} # type: ignore - @distributed_trace def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -808,12 +802,11 @@ def get( 'properties($expand=artifacts,computeVm,networkInterface,applicableSchedule)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabVirtualMachine or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabVirtualMachine :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -824,27 +817,24 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachine] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.LabVirtualMachine] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -853,24 +843,22 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) + deserialized = self._deserialize("LabVirtualMachine", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( self, resource_group_name: str, lab_name: str, name: str, - lab_virtual_machine: Union[_models.LabVirtualMachine, IO], + lab_virtual_machine: Union[_models.LabVirtualMachine, IO[bytes]], **kwargs: Any - ) -> _models.LabVirtualMachine: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -881,21 +869,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachine] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(lab_virtual_machine, (IO, bytes)): + if isinstance(lab_virtual_machine, (IOBase, bytes)): _content = lab_virtual_machine else: _json = self._serialize.body(lab_virtual_machine, "LabVirtualMachine") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -904,35 +890,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -958,14 +942,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either LabVirtualMachine or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.LabVirtualMachine] @@ -978,7 +954,7 @@ def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - lab_virtual_machine: IO, + lab_virtual_machine: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -992,18 +968,10 @@ def begin_create_or_update( :param name: The name of the virtual machine. Required. :type name: str :param lab_virtual_machine: A virtual machine. Required. - :type lab_virtual_machine: IO + :type lab_virtual_machine: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either LabVirtualMachine or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.LabVirtualMachine] @@ -1016,7 +984,7 @@ def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - lab_virtual_machine: Union[_models.LabVirtualMachine, IO], + lab_virtual_machine: Union[_models.LabVirtualMachine, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.LabVirtualMachine]: """Create or replace an existing virtual machine. This operation can take a while to complete. @@ -1027,19 +995,9 @@ def begin_create_or_update( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :param lab_virtual_machine: A virtual machine. Is either a model type or a IO type. Required. - :type lab_virtual_machine: ~azure.mgmt.devtestlabs.models.LabVirtualMachine or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param lab_virtual_machine: A virtual machine. Is either a LabVirtualMachine type or a + IO[bytes] type. Required. + :type lab_virtual_machine: ~azure.mgmt.devtestlabs.models.LabVirtualMachine or IO[bytes] :return: An instance of LROPoller that returns either LabVirtualMachine or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.LabVirtualMachine] @@ -1048,16 +1006,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachine] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.LabVirtualMachine] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1069,35 +1025,34 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) + deserialized = self._deserialize("LabVirtualMachine", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.LabVirtualMachine].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return LROPoller[_models.LabVirtualMachine]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _delete_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1108,38 +1063,42 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -1151,14 +1110,6 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1166,15 +1117,13 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1184,28 +1133,27 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def update( @@ -1221,12 +1169,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: LabVirtualMachine or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.LabVirtualMachine :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1237,16 +1184,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.LabVirtualMachine] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.LabVirtualMachine] = kwargs.pop("cls", None) _lab_virtual_machine = _models.LabVirtualMachineFragment(tags=tags) _json = self._serialize.body(_lab_virtual_machine, "LabVirtualMachineFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1254,15 +1199,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1271,24 +1215,22 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("LabVirtualMachine", pipeline_response) + deserialized = self._deserialize("LabVirtualMachine", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - return deserialized + return deserialized # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}"} # type: ignore - - def _add_data_disk_initial( # pylint: disable=inconsistent-return-statements + def _add_data_disk_initial( self, resource_group_name: str, lab_name: str, name: str, - data_disk_properties: Union[_models.DataDiskProperties, IO], + data_disk_properties: Union[_models.DataDiskProperties, IO[bytes]], **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1299,21 +1241,19 @@ def _add_data_disk_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(data_disk_properties, (IO, bytes)): + if isinstance(data_disk_properties, (IOBase, bytes)): _content = data_disk_properties else: _json = self._serialize.body(data_disk_properties, "DataDiskProperties") - request = build_add_data_disk_request( + _request = build_add_data_disk_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1322,27 +1262,33 @@ def _add_data_disk_initial( # pylint: disable=inconsistent-return-statements content_type=content_type, json=_json, content=_content, - template_url=self._add_data_disk_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _add_data_disk_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/addDataDisk"} # type: ignore + return deserialized # type: ignore @overload def begin_add_data_disk( @@ -1370,14 +1316,6 @@ def begin_add_data_disk( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1389,7 +1327,7 @@ def begin_add_data_disk( resource_group_name: str, lab_name: str, name: str, - data_disk_properties: IO, + data_disk_properties: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -1405,18 +1343,10 @@ def begin_add_data_disk( :type name: str :param data_disk_properties: Request body for adding a new or existing data disk to a virtual machine. Required. - :type data_disk_properties: IO + :type data_disk_properties: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1428,7 +1358,7 @@ def begin_add_data_disk( resource_group_name: str, lab_name: str, name: str, - data_disk_properties: Union[_models.DataDiskProperties, IO], + data_disk_properties: Union[_models.DataDiskProperties, IO[bytes]], **kwargs: Any ) -> LROPoller[None]: """Attach a new or existing data disk to virtual machine. This operation can take a while to @@ -1441,19 +1371,8 @@ def begin_add_data_disk( :param name: The name of the virtual machine. Required. :type name: str :param data_disk_properties: Request body for adding a new or existing data disk to a virtual - machine. Is either a model type or a IO type. Required. - :type data_disk_properties: ~azure.mgmt.devtestlabs.models.DataDiskProperties or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + machine. Is either a DataDiskProperties type or a IO[bytes] type. Required. + :type data_disk_properties: ~azure.mgmt.devtestlabs.models.DataDiskProperties or IO[bytes] :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1461,16 +1380,14 @@ def begin_add_data_disk( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._add_data_disk_initial( # type: ignore + raw_result = self._add_data_disk_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1482,38 +1399,37 @@ def begin_add_data_disk( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_add_data_disk.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/addDataDisk"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _apply_artifacts_initial( # pylint: disable=inconsistent-return-statements + def _apply_artifacts_initial( self, resource_group_name: str, lab_name: str, name: str, artifacts: Optional[List[_models.ArtifactInstallProperties]] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1524,16 +1440,14 @@ def _apply_artifacts_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) _apply_artifacts_request = _models.ApplyArtifactsRequest(artifacts=artifacts) _json = self._serialize.body(_apply_artifacts_request, "ApplyArtifactsRequest") - request = build_apply_artifacts_request( + _request = build_apply_artifacts_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1541,27 +1455,33 @@ def _apply_artifacts_initial( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self._apply_artifacts_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _apply_artifacts_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/applyArtifacts"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_apply_artifacts( @@ -1582,14 +1502,6 @@ def begin_apply_artifacts( :type name: str :param artifacts: The list of artifacts to apply. Default value is None. :type artifacts: list[~azure.mgmt.devtestlabs.models.ArtifactInstallProperties] - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1597,16 +1509,14 @@ def begin_apply_artifacts( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._apply_artifacts_initial( # type: ignore + raw_result = self._apply_artifacts_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1618,33 +1528,30 @@ def begin_apply_artifacts( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_apply_artifacts.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/applyArtifacts"} # type: ignore - - def _claim_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _claim_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1655,38 +1562,42 @@ def _claim_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_claim_request( + _request = build_claim_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._claim_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _claim_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/claim"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_claim(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -1698,14 +1609,6 @@ def begin_claim(self, resource_group_name: str, lab_name: str, name: str, **kwar :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1713,15 +1616,13 @@ def begin_claim(self, resource_group_name: str, lab_name: str, name: str, **kwar _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._claim_initial( # type: ignore + raw_result = self._claim_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1731,38 +1632,37 @@ def begin_claim(self, resource_group_name: str, lab_name: str, name: str, **kwar params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - begin_claim.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/claim"} # type: ignore - - def _detach_data_disk_initial( # pylint: disable=inconsistent-return-statements + def _detach_data_disk_initial( self, resource_group_name: str, lab_name: str, name: str, existing_lab_disk_id: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1773,16 +1673,14 @@ def _detach_data_disk_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) _detach_data_disk_properties = _models.DetachDataDiskProperties(existing_lab_disk_id=existing_lab_disk_id) _json = self._serialize.body(_detach_data_disk_properties, "DetachDataDiskProperties") - request = build_detach_data_disk_request( + _request = build_detach_data_disk_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1790,27 +1688,33 @@ def _detach_data_disk_initial( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self._detach_data_disk_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _detach_data_disk_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/detachDataDisk"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_detach_data_disk( @@ -1833,14 +1737,6 @@ def begin_detach_data_disk( :param existing_lab_disk_id: Specifies the disk resource ID to detach from virtual machine. Default value is None. :type existing_lab_disk_id: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -1848,16 +1744,14 @@ def begin_detach_data_disk( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._detach_data_disk_initial( # type: ignore + raw_result = self._detach_data_disk_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -1869,28 +1763,27 @@ def begin_detach_data_disk( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_detach_data_disk.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/detachDataDisk"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def get_rdp_file_contents( @@ -1904,12 +1797,11 @@ def get_rdp_file_contents( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: RdpConnection or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.RdpConnection :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1920,26 +1812,23 @@ def get_rdp_file_contents( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.RdpConnection] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.RdpConnection] = kwargs.pop("cls", None) - request = build_get_rdp_file_contents_request( + _request = build_get_rdp_file_contents_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.get_rdp_file_contents.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -1948,14 +1837,12 @@ def get_rdp_file_contents( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("RdpConnection", pipeline_response) + deserialized = self._deserialize("RdpConnection", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get_rdp_file_contents.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/getRdpFileContents"} # type: ignore + return deserialized # type: ignore @distributed_trace def list_applicable_schedules( @@ -1969,12 +1856,11 @@ def list_applicable_schedules( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: ApplicableSchedule or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.ApplicableSchedule :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -1985,26 +1871,23 @@ def list_applicable_schedules( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.ApplicableSchedule] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.ApplicableSchedule] = kwargs.pop("cls", None) - request = build_list_applicable_schedules_request( + _request = build_list_applicable_schedules_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self.list_applicable_schedules.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -2013,19 +1896,15 @@ def list_applicable_schedules( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("ApplicableSchedule", pipeline_response) + deserialized = self._deserialize("ApplicableSchedule", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - list_applicable_schedules.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/listApplicableSchedules"} # type: ignore + return deserialized # type: ignore - def _redeploy_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _redeploy_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2036,38 +1915,42 @@ def _redeploy_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_redeploy_request( + _request = build_redeploy_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._redeploy_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _redeploy_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/redeploy"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_redeploy(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -2079,14 +1962,6 @@ def begin_redeploy(self, resource_group_name: str, lab_name: str, name: str, **k :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -2094,15 +1969,13 @@ def begin_redeploy(self, resource_group_name: str, lab_name: str, name: str, **k _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._redeploy_initial( # type: ignore + raw_result = self._redeploy_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2112,33 +1985,32 @@ def begin_redeploy(self, resource_group_name: str, lab_name: str, name: str, **k params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_redeploy.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/redeploy"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _resize_initial( # pylint: disable=inconsistent-return-statements + def _resize_initial( self, resource_group_name: str, lab_name: str, name: str, size: Optional[str] = None, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2149,16 +2021,14 @@ def _resize_initial( # pylint: disable=inconsistent-return-statements _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) _resize_lab_virtual_machine_properties = _models.ResizeLabVirtualMachineProperties(size=size) _json = self._serialize.body(_resize_lab_virtual_machine_properties, "ResizeLabVirtualMachineProperties") - request = build_resize_request( + _request = build_resize_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2166,27 +2036,33 @@ def _resize_initial( # pylint: disable=inconsistent-return-statements api_version=api_version, content_type=content_type, json=_json, - template_url=self._resize_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _resize_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/resize"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_resize( @@ -2202,14 +2078,6 @@ def begin_resize( :type name: str :param size: Specifies the size of the virtual machine. Default value is None. :type size: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -2217,16 +2085,14 @@ def begin_resize( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._resize_initial( # type: ignore + raw_result = self._resize_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2238,33 +2104,30 @@ def begin_resize( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_resize.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/resize"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _restart_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _restart_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2275,38 +2138,42 @@ def _restart_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_restart_request( + _request = build_restart_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._restart_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _restart_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/restart"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_restart(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -2318,14 +2185,6 @@ def begin_restart(self, resource_group_name: str, lab_name: str, name: str, **kw :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -2333,15 +2192,13 @@ def begin_restart(self, resource_group_name: str, lab_name: str, name: str, **kw _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._restart_initial( # type: ignore + raw_result = self._restart_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2351,33 +2208,30 @@ def begin_restart(self, resource_group_name: str, lab_name: str, name: str, **kw params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_restart.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/restart"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _start_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _start_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2388,38 +2242,42 @@ def _start_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_start_request( + _request = build_start_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._start_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _start_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/start"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_start(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -2431,14 +2289,6 @@ def begin_start(self, resource_group_name: str, lab_name: str, name: str, **kwar :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -2446,15 +2296,13 @@ def begin_start(self, resource_group_name: str, lab_name: str, name: str, **kwar _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._start_initial( # type: ignore + raw_result = self._start_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2464,33 +2312,30 @@ def begin_start(self, resource_group_name: str, lab_name: str, name: str, **kwar params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_start.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/start"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _stop_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _stop_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2501,38 +2346,42 @@ def _stop_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_stop_request( + _request = build_stop_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._stop_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _stop_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/stop"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_stop(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -2544,14 +2393,6 @@ def begin_stop(self, resource_group_name: str, lab_name: str, name: str, **kwarg :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -2559,15 +2400,13 @@ def begin_stop(self, resource_group_name: str, lab_name: str, name: str, **kwarg _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._stop_initial( # type: ignore + raw_result = self._stop_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2577,33 +2416,32 @@ def begin_stop(self, resource_group_name: str, lab_name: str, name: str, **kwarg params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_stop.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/stop"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _transfer_disks_initial( # pylint: disable=inconsistent-return-statements + def _transfer_disks_initial( self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2614,38 +2452,42 @@ def _transfer_disks_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_transfer_disks_request( + _request = build_transfer_disks_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._transfer_disks_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _transfer_disks_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/transferDisks"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_transfer_disks( @@ -2660,14 +2502,6 @@ def begin_transfer_disks( :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -2675,15 +2509,13 @@ def begin_transfer_disks( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._transfer_disks_initial( # type: ignore + raw_result = self._transfer_disks_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2693,33 +2525,30 @@ def begin_transfer_disks( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_transfer_disks.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/transferDisks"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore - def _un_claim_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _un_claim_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -2730,38 +2559,42 @@ def _un_claim_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_un_claim_request( + _request = build_un_claim_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._un_claim_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _un_claim_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/unClaim"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_un_claim(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -2773,14 +2606,6 @@ def begin_un_claim(self, resource_group_name: str, lab_name: str, name: str, **k :type lab_name: str :param name: The name of the virtual machine. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -2788,15 +2613,13 @@ def begin_un_claim(self, resource_group_name: str, lab_name: str, name: str, **k _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._un_claim_initial( # type: ignore + raw_result = self._un_claim_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -2806,25 +2629,24 @@ def begin_un_claim(self, resource_group_name: str, lab_name: str, name: str, **k params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_un_claim.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/unClaim"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_networks_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_networks_operations.py index af9454018320..97a3ba34e5e2 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_networks_operations.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/azure/mgmt/devtestlabs/operations/_virtual_networks_operations.py @@ -1,4 +1,4 @@ -# pylint: disable=too-many-lines +# pylint: disable=too-many-lines,too-many-statements # coding=utf-8 # -------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,8 +6,9 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys -from typing import Any, Callable, Dict, IO, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Dict, IO, Iterable, Iterator, Optional, Type, TypeVar, Union, cast, overload import urllib.parse from azure.core.exceptions import ( @@ -16,13 +17,14 @@ ResourceExistsError, ResourceNotFoundError, ResourceNotModifiedError, + StreamClosedError, + StreamConsumedError, map_error, ) from azure.core.paging import ItemPaged from azure.core.pipeline import PipelineResponse -from azure.core.pipeline.transport import HttpResponse from azure.core.polling import LROPoller, NoPolling, PollingMethod -from azure.core.rest import HttpRequest +from azure.core.rest import HttpRequest, HttpResponse from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict from azure.mgmt.core.exceptions import ARMErrorFormat @@ -30,12 +32,11 @@ from .. import models as _models from .._serialization import Serializer -from .._vendor import _convert_request, _format_url_section -if sys.version_info >= (3, 8): - from typing import Literal # pylint: disable=no-name-in-module, ungrouped-imports +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping else: - from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -57,7 +58,7 @@ def build_list_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -71,7 +72,7 @@ def build_list_request( "labName": _SERIALIZER.url("lab_name", lab_name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -102,7 +103,7 @@ def build_get_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -117,7 +118,7 @@ def build_get_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters if expand is not None: @@ -136,8 +137,8 @@ def build_create_or_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -152,7 +153,7 @@ def build_create_or_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -171,7 +172,7 @@ def build_delete_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -186,7 +187,7 @@ def build_delete_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -203,8 +204,8 @@ def build_update_request( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", "2018-09-15")) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) accept = _headers.pop("Accept", "application/json") # Construct URL @@ -219,7 +220,7 @@ def build_update_request( "name": _SERIALIZER.url("name", name, "str"), } - _url = _format_url_section(_url, **path_format_arguments) + _url: str = _url.format(**path_format_arguments) # type: ignore # Construct parameters _params["api-version"] = _SERIALIZER.query("api_version", api_version, "str") @@ -280,7 +281,6 @@ def list( :param orderby: The ordering expression for the results, using OData notation. Example: '$orderby=name desc'. Default value is None. :type orderby: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: An iterator like instance of either VirtualNetwork or the result of cls(response) :rtype: ~azure.core.paging.ItemPaged[~azure.mgmt.devtestlabs.models.VirtualNetwork] :raises ~azure.core.exceptions.HttpResponseError: @@ -288,12 +288,10 @@ def list( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetworkList] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.VirtualNetworkList] = kwargs.pop("cls", None) - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -304,7 +302,7 @@ def list( def prepare_request(next_link=None): if not next_link: - request = build_list_request( + _request = build_list_request( resource_group_name=resource_group_name, lab_name=lab_name, subscription_id=self._config.subscription_id, @@ -313,12 +311,10 @@ def prepare_request(next_link=None): top=top, orderby=orderby, api_version=api_version, - template_url=self.list.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) else: # make call to next link with the client's api-version @@ -330,26 +326,26 @@ def prepare_request(next_link=None): } ) _next_request_params["api-version"] = self._config.api_version - request = HttpRequest( + _request = HttpRequest( "GET", urllib.parse.urljoin(next_link, _parsed_next_link.path), params=_next_request_params ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore - request.method = "GET" - return request + _request.url = self._client.format_url(_request.url) + _request.method = "GET" + return _request def extract_data(pipeline_response): deserialized = self._deserialize("VirtualNetworkList", pipeline_response) list_of_elem = deserialized.value if cls: - list_of_elem = cls(list_of_elem) + list_of_elem = cls(list_of_elem) # type: ignore return deserialized.next_link or None, iter(list_of_elem) def get_next(next_link=None): - request = prepare_request(next_link) + _request = prepare_request(next_link) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -361,8 +357,6 @@ def get_next(next_link=None): return ItemPaged(get_next, extract_data) - list.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks"} # type: ignore - @distributed_trace def get( self, resource_group_name: str, lab_name: str, name: str, expand: Optional[str] = None, **kwargs: Any @@ -378,12 +372,11 @@ def get( :param expand: Specify the $expand query. Example: 'properties($expand=externalSubnets)'. Default value is None. :type expand: str - :keyword callable cls: A custom type or function that will be passed the direct response :return: VirtualNetwork or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.VirtualNetwork :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -394,27 +387,24 @@ def get( _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetwork] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[_models.VirtualNetwork] = kwargs.pop("cls", None) - request = build_get_request( + _request = build_get_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, expand=expand, api_version=api_version, - template_url=self.get.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -423,24 +413,22 @@ def get( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("VirtualNetwork", pipeline_response) + deserialized = self._deserialize("VirtualNetwork", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - get.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return deserialized # type: ignore def _create_or_update_initial( self, resource_group_name: str, lab_name: str, name: str, - virtual_network: Union[_models.VirtualNetwork, IO], + virtual_network: Union[_models.VirtualNetwork, IO[bytes]], **kwargs: Any - ) -> _models.VirtualNetwork: - error_map = { + ) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -451,21 +439,19 @@ def _create_or_update_initial( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetwork] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) content_type = content_type or "application/json" _json = None _content = None - if isinstance(virtual_network, (IO, bytes)): + if isinstance(virtual_network, (IOBase, bytes)): _content = virtual_network else: _json = self._serialize.body(virtual_network, "VirtualNetwork") - request = build_create_or_update_request( + _request = build_create_or_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -474,35 +460,33 @@ def _create_or_update_initial( content_type=content_type, json=_json, content=_content, - template_url=self._create_or_update_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 201]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - if response.status_code == 200: - deserialized = self._deserialize("VirtualNetwork", pipeline_response) - - if response.status_code == 201: - deserialized = self._deserialize("VirtualNetwork", pipeline_response) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - _create_or_update_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return deserialized # type: ignore @overload def begin_create_or_update( @@ -528,14 +512,6 @@ def begin_create_or_update( :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either VirtualNetwork or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.VirtualNetwork] @@ -548,7 +524,7 @@ def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - virtual_network: IO, + virtual_network: IO[bytes], *, content_type: str = "application/json", **kwargs: Any @@ -562,18 +538,10 @@ def begin_create_or_update( :param name: The name of the virtual network. Required. :type name: str :param virtual_network: A virtual network. Required. - :type virtual_network: IO + :type virtual_network: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either VirtualNetwork or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.VirtualNetwork] @@ -586,7 +554,7 @@ def begin_create_or_update( resource_group_name: str, lab_name: str, name: str, - virtual_network: Union[_models.VirtualNetwork, IO], + virtual_network: Union[_models.VirtualNetwork, IO[bytes]], **kwargs: Any ) -> LROPoller[_models.VirtualNetwork]: """Create or replace an existing virtual network. This operation can take a while to complete. @@ -597,19 +565,9 @@ def begin_create_or_update( :type lab_name: str :param name: The name of the virtual network. Required. :type name: str - :param virtual_network: A virtual network. Is either a model type or a IO type. Required. - :type virtual_network: ~azure.mgmt.devtestlabs.models.VirtualNetwork or IO - :keyword content_type: Body Parameter content-type. Known values are: 'application/json'. - Default value is None. - :paramtype content_type: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. + :param virtual_network: A virtual network. Is either a VirtualNetwork type or a IO[bytes] type. + Required. + :type virtual_network: ~azure.mgmt.devtestlabs.models.VirtualNetwork or IO[bytes] :return: An instance of LROPoller that returns either VirtualNetwork or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[~azure.mgmt.devtestlabs.models.VirtualNetwork] @@ -618,16 +576,14 @@ def begin_create_or_update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", None)) # type: Optional[str] - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetwork] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: Optional[str] = kwargs.pop("content_type", _headers.pop("Content-Type", None)) + cls: ClsType[_models.VirtualNetwork] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._create_or_update_initial( # type: ignore + raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -639,35 +595,34 @@ def begin_create_or_update( params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): - deserialized = self._deserialize("VirtualNetwork", pipeline_response) + deserialized = self._deserialize("VirtualNetwork", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore return deserialized if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[_models.VirtualNetwork].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_create_or_update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return LROPoller[_models.VirtualNetwork]( + self._client, raw_result, get_long_running_output, polling_method # type: ignore + ) - def _delete_initial( # pylint: disable=inconsistent-return-statements - self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any - ) -> None: - error_map = { + def _delete_initial(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> Iterator[bytes]: + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -678,38 +633,42 @@ def _delete_initial( # pylint: disable=inconsistent-return-statements _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[Iterator[bytes]] = kwargs.pop("cls", None) - request = build_delete_request( + _request = build_delete_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, subscription_id=self._config.subscription_id, api_version=api_version, - template_url=self._delete_initial.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _decompress = kwargs.pop("decompress", True) + _stream = True + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response if response.status_code not in [200, 202, 204]: + try: + response.read() # Load the body in memory and close the socket + except (StreamConsumedError, StreamClosedError): + pass map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) + deserialized = response.stream_download(self._client._pipeline, decompress=_decompress) + if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, deserialized, {}) # type: ignore - _delete_initial.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return deserialized # type: ignore @distributed_trace def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwargs: Any) -> LROPoller[None]: @@ -721,14 +680,6 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa :type lab_name: str :param name: The name of the virtual network. Required. :type name: str - :keyword callable cls: A custom type or function that will be passed the direct response - :keyword str continuation_token: A continuation token to restart a poller from a saved state. - :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this - operation to not poll, or pass in your own initialized polling object for a personal polling - strategy. - :paramtype polling: bool or ~azure.core.polling.PollingMethod - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no - Retry-After header is present. :return: An instance of LROPoller that returns either None or the result of cls(response) :rtype: ~azure.core.polling.LROPoller[None] :raises ~azure.core.exceptions.HttpResponseError: @@ -736,15 +687,13 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa _headers = kwargs.pop("headers", {}) or {} _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - cls = kwargs.pop("cls", None) # type: ClsType[None] - polling = kwargs.pop("polling", True) # type: Union[bool, PollingMethod] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + cls: ClsType[None] = kwargs.pop("cls", None) + polling: Union[bool, PollingMethod] = kwargs.pop("polling", True) lro_delay = kwargs.pop("polling_interval", self._config.polling_interval) - cont_token = kwargs.pop("continuation_token", None) # type: Optional[str] + cont_token: Optional[str] = kwargs.pop("continuation_token", None) if cont_token is None: - raw_result = self._delete_initial( # type: ignore + raw_result = self._delete_initial( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -754,28 +703,27 @@ def begin_delete(self, resource_group_name: str, lab_name: str, name: str, **kwa params=_params, **kwargs ) + raw_result.http_response.read() # type: ignore kwargs.pop("error_map", None) def get_long_running_output(pipeline_response): # pylint: disable=inconsistent-return-statements if cls: - return cls(pipeline_response, None, {}) + return cls(pipeline_response, None, {}) # type: ignore if polling is True: - polling_method = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) # type: PollingMethod + polling_method: PollingMethod = cast(PollingMethod, ARMPolling(lro_delay, **kwargs)) elif polling is False: polling_method = cast(PollingMethod, NoPolling()) else: polling_method = polling if cont_token: - return LROPoller.from_continuation_token( + return LROPoller[None].from_continuation_token( polling_method=polling_method, continuation_token=cont_token, client=self._client, deserialization_callback=get_long_running_output, ) - return LROPoller(self._client, raw_result, get_long_running_output, polling_method) - - begin_delete.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return LROPoller[None](self._client, raw_result, get_long_running_output, polling_method) # type: ignore @distributed_trace def update( @@ -791,12 +739,11 @@ def update( :type name: str :param tags: The tags of the resource. Default value is None. :type tags: dict[str, str] - :keyword callable cls: A custom type or function that will be passed the direct response :return: VirtualNetwork or the result of cls(response) :rtype: ~azure.mgmt.devtestlabs.models.VirtualNetwork :raises ~azure.core.exceptions.HttpResponseError: """ - error_map = { + error_map: MutableMapping[int, Type[HttpResponseError]] = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError, @@ -807,16 +754,14 @@ def update( _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) - api_version = kwargs.pop( - "api_version", _params.pop("api-version", self._config.api_version) - ) # type: Literal["2018-09-15"] - content_type = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) # type: str - cls = kwargs.pop("cls", None) # type: ClsType[_models.VirtualNetwork] + api_version: str = kwargs.pop("api_version", _params.pop("api-version", self._config.api_version)) + content_type: str = kwargs.pop("content_type", _headers.pop("Content-Type", "application/json")) + cls: ClsType[_models.VirtualNetwork] = kwargs.pop("cls", None) _virtual_network = _models.VirtualNetworkFragment(tags=tags) _json = self._serialize.body(_virtual_network, "VirtualNetworkFragment") - request = build_update_request( + _request = build_update_request( resource_group_name=resource_group_name, lab_name=lab_name, name=name, @@ -824,15 +769,14 @@ def update( api_version=api_version, content_type=content_type, json=_json, - template_url=self.update.metadata["url"], headers=_headers, params=_params, ) - request = _convert_request(request) - request.url = self._client.format_url(request.url) # type: ignore + _request.url = self._client.format_url(_request.url) - pipeline_response = self._client._pipeline.run( # type: ignore # pylint: disable=protected-access - request, stream=False, **kwargs + _stream = False + pipeline_response: PipelineResponse = self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs ) response = pipeline_response.http_response @@ -841,11 +785,9 @@ def update( map_error(status_code=response.status_code, response=response, error_map=error_map) raise HttpResponseError(response=response, error_format=ARMErrorFormat) - deserialized = self._deserialize("VirtualNetwork", pipeline_response) + deserialized = self._deserialize("VirtualNetwork", pipeline_response.http_response) if cls: - return cls(pipeline_response, deserialized, {}) - - return deserialized + return cls(pipeline_response, deserialized, {}) # type: ignore - update.metadata = {"url": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualnetworks/{name}"} # type: ignore + return deserialized # type: ignore diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/dev_requirements.txt b/sdk/devtestlabs/azure-mgmt-devtestlabs/dev_requirements.txt index e06c927d8089..eea05d9a0cb1 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/dev_requirements.txt +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/dev_requirements.txt @@ -1,3 +1,4 @@ -e ../../../tools/azure-sdk-tools -e ../../resources/azure-mgmt-resource -../../identity/azure-identity \ No newline at end of file +../../identity/azure-identity +aiohttp \ No newline at end of file diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/arm_templates_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/arm_templates_get.py index 732df091c0d9..2c04a599ad2d 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/arm_templates_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/arm_templates_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/arm_templates_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/arm_templates_list.py index 567af68cd353..31665db0eba8 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/arm_templates_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/arm_templates_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_create_or_update.py index 95cb83c42a82..f456b864fdfb 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_delete.py index 9757364ab86d..633565c30dd8 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.artifact_sources.delete( + client.artifact_sources.delete( resource_group_name="resourceGroupName", lab_name="{labName}", name="{artifactSourceName}", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/ArtifactSources_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_get.py index ecadac32b200..b976a9b5403e 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_list.py index b71c05d8b648..03cad693f88d 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_update.py index 7ce39fd2740d..42deaa84984e 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifact_sources_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_generate_arm_template.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_generate_arm_template.py index a003c705a73f..447a00b0e94e 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_generate_arm_template.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_generate_arm_template.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_get.py index ef632c0ebd2b..cecdebe82ed5 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_list.py index b94a8032ae82..af61f1720e25 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/artifacts_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/costs_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/costs_create_or_update.py index ff82e146e980..67b2012d0e7b 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/costs_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/costs_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/costs_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/costs_get.py index f5de5aa7a75f..e5096484a040 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/costs_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/costs_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_create_or_update.py index 93c27f17e068..3de0e27500ff 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_delete.py index 3a595928e3b2..cfcec87172d4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.custom_images.begin_delete( + client.custom_images.begin_delete( resource_group_name="resourceGroupName", lab_name="{labName}", name="{customImageName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/CustomImages_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_get.py index f4201dc637ea..d4054efdc2f0 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_list.py index 146137b70d06..de930a988251 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_update.py index 2d8db559ca44..bb55d69e28f6 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/custom_images_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_attach.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_attach.py index 9e840d33f90e..f161f51d0e61 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_attach.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_attach.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.disks.begin_attach( + client.disks.begin_attach( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="{userId}", name="{diskName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Disks_Attach.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_create_or_update.py index e702ea503967..07910b2d30a2 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_delete.py index 1faeda54163e..c311a37845ca 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.disks.begin_delete( + client.disks.begin_delete( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="{userId}", name="{diskName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Disks_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_detach.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_detach.py index 682b8509b0bb..f85e9a1e40f3 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_detach.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_detach.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.disks.begin_detach( + client.disks.begin_detach( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="{userId}", name="{diskName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Disks_Detach.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_get.py index 58f87e853d35..180dffad5c72 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_list.py index daec7331626d..509ce2946bfd 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_update.py index da492ab7a2ab..213aef75c703 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/disks_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_create_or_update.py index 0fd602e59468..ad6706bdfbbb 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_delete.py index a1a7d0b937ce..db719a16369d 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.environments.begin_delete( + client.environments.begin_delete( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="@me", name="{environmentName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Environments_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_get.py index 3e676829a6ba..4f7d412bdb91 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_list.py index 616f63297df7..8bc2112ead25 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_update.py index ef2673ddb54f..b6240437446a 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/environments_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_create_or_update.py index 24c94f81b697..e4325e3be968 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_delete.py index 939f2bb1b759..e75cf75bfaa0 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.formulas.delete( + client.formulas.delete( resource_group_name="resourceGroupName", lab_name="{labName}", name="{formulaName}", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Formulas_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_get.py index 811c20ebc9bb..d4060d0a1e65 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_list.py index 8de7b28b62f1..e802be566fe4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_update.py index ec6cc59d86b7..407090b7c00b 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/formulas_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/gallery_images_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/gallery_images_list.py index 87bbd2035846..fdedb2fcace1 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/gallery_images_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/gallery_images_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_create_or_update.py index 8a870e99a5d4..ac91a3e27561 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_delete.py index 62744af4e38d..525cd6b65db4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,11 +30,10 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.global_schedules.delete( + client.global_schedules.delete( resource_group_name="resourceGroupName", name="labvmautostart", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/GlobalSchedules_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_execute.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_execute.py index 4fd66179a15a..02160d736a06 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_execute.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_execute.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,11 +30,10 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.global_schedules.begin_execute( + client.global_schedules.begin_execute( resource_group_name="resourceGroupName", name="labvmautostart", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/GlobalSchedules_Execute.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_get.py index 42f4659e55d1..a579cd240ef4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_list_by_resource_group.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_list_by_resource_group.py index 0037b668c8c6..30d0f81c7cea 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_list_by_resource_group.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_list_by_resource_group.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_list_by_subscription.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_list_by_subscription.py index e4815d3c35c5..3b2b23d0a0f5 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_list_by_subscription.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_list_by_subscription.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_retarget.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_retarget.py index 79651d75e2d7..a6328c290e2e 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_retarget.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_retarget.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,11 +30,10 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.global_schedules.begin_retarget( + client.global_schedules.begin_retarget( resource_group_name="resourceGroupName", name="{scheduleName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/GlobalSchedules_Retarget.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_update.py index 66f159ce168c..8bd9593307c0 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/global_schedules_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_claim_any_vm.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_claim_any_vm.py index 745784fb0c58..e99daa36e385 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_claim_any_vm.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_claim_any_vm.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,11 +30,10 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.labs.begin_claim_any_vm( + client.labs.begin_claim_any_vm( resource_group_name="resourceGroupName", name="{labName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Labs_ClaimAnyVm.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_create_environment.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_create_environment.py index 3996c9e69571..bb699cf32526 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_create_environment.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_create_environment.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,7 +30,7 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.labs.begin_create_environment( + client.labs.begin_create_environment( resource_group_name="resourceGroupName", name="{labName}", lab_virtual_machine_creation_parameter={ @@ -55,7 +56,6 @@ def main(): "tags": {"tagName1": "tagValue1"}, }, ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Labs_CreateEnvironment.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_create_or_update.py index ce9cd7437531..7d6d9656551d 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_delete.py index 23ff73017edc..cd7b675e3fa4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,11 +30,10 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.labs.begin_delete( + client.labs.begin_delete( resource_group_name="resourceGroupName", name="{labName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Labs_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_export_resource_usage.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_export_resource_usage.py index c11e48ff81ae..30c1d8e72360 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_export_resource_usage.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_export_resource_usage.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,11 +30,10 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.labs.begin_export_resource_usage( + client.labs.begin_export_resource_usage( resource_group_name="resourceGroupName", name="{labName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Labs_ExportResourceUsage.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_generate_upload_uri.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_generate_upload_uri.py index 55f60c2d98c0..c7f7ba1d5cab 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_generate_upload_uri.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_generate_upload_uri.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_get.py index a6b381ed8498..545ccbb8147e 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_import_virtual_machine.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_import_virtual_machine.py index 0d0a353b62b5..c75f13a5f756 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_import_virtual_machine.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_import_virtual_machine.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,11 +30,10 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.labs.begin_import_virtual_machine( + client.labs.begin_import_virtual_machine( resource_group_name="resourceGroupName", name="{labName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Labs_ImportVirtualMachine.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_by_resource_group.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_by_resource_group.py index 9a3c761d4541..876a67b7aac0 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_by_resource_group.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_by_resource_group.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_by_subscription.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_by_subscription.py index 9e539c8338fb..852b6abad7b6 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_by_subscription.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_by_subscription.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_vhds.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_vhds.py index 1074a444ff8e..3e0d6df9b0bd 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_vhds.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_list_vhds.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_update.py index c596c2cecd17..53b1694f6c94 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/labs_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_create_or_update.py index caf8f96a0252..1cc089ad471e 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_delete.py index 07fb6bdfe5d0..42610a86f74e 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.notification_channels.delete( + client.notification_channels.delete( resource_group_name="resourceGroupName", lab_name="{labName}", name="{notificationChannelName}", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/NotificationChannels_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_get.py index a506e1468c04..1b0d2d83ff91 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_list.py index 0648ddadc163..69c6e558e74b 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_notify.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_notify.py index 261b3941ba4e..19ca67908d87 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_notify.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_notify.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.notification_channels.notify( + client.notification_channels.notify( resource_group_name="resourceGroupName", lab_name="{labName}", name="{notificationChannelName}", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/NotificationChannels_Notify.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_update.py index fdf5cff66e9d..7bffb40c75eb 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/notification_channels_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/operations_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/operations_get.py index 07e70d5b6316..30e8a6803fba 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/operations_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/operations_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_create_or_update.py index 1a95060b1ca0..3d77cbbe8618 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_delete.py index 3da1df2fd5c8..1d73c99572e4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.policies.delete( + client.policies.delete( resource_group_name="resourceGroupName", lab_name="{labName}", policy_set_name="{policySetName}", name="{policyName}", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Policies_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_get.py index b6cf5ed57a1b..0006ce40f228 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_list.py index 1e4f4d26c0ff..6e829b741b01 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_update.py index 97fa7e21d3a8..3502634120b6 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policies_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policy_sets_evaluate_policies.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policy_sets_evaluate_policies.py index d3a599707a82..dd32a55df800 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policy_sets_evaluate_policies.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/policy_sets_evaluate_policies.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/provider_operations_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/provider_operations_list.py index fb71cb0eb23c..6f2fc22a588f 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/provider_operations_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/provider_operations_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_create_or_update.py index a3ebc2e7a0df..089b8fdc3e4b 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_delete.py index 00ebac8f7ba9..7fa423f31777 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.schedules.delete( + client.schedules.delete( resource_group_name="resourceGroupName", lab_name="{labName}", name="{scheduleName}", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Schedules_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_execute.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_execute.py index 419268570421..8cb997948a14 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_execute.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_execute.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.schedules.begin_execute( + client.schedules.begin_execute( resource_group_name="resourceGroupName", lab_name="{labName}", name="{scheduleName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Schedules_Execute.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_get.py index db0599fa03fd..ae53aea5d660 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_list.py index 488a52fe9dce..a0a42efe95b4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_list_applicable.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_list_applicable.py index 1920dfb1e7ac..abcde96d9463 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_list_applicable.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_list_applicable.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_update.py index b9e6000a8cf4..42e650d27328 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/schedules_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_create_or_update.py index f9d4f4c1bf0d..f9cc7708d99c 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_delete.py index 7586df053724..61c606ebf2ca 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.secrets.delete( + client.secrets.delete( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="{userName}", name="{secretName}", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Secrets_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_get.py index eef7db1ceda3..22d686eeacc7 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_list.py index 4dcd3064db73..f5c86992f1c0 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_update.py index 1786d22a2da0..a4470ea7d1b8 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/secrets_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_create_or_update.py index 8e04d3d7aa01..fca2e6c97f85 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_delete.py index 37437bfca16d..2a265a247625 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,14 +30,13 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.service_fabric_schedules.delete( + client.service_fabric_schedules.delete( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="@me", service_fabric_name="{serviceFrabicName}", name="{scheduleName}", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/ServiceFabricSchedules_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_execute.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_execute.py index feb54e9c429b..9f97f8e14cda 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_execute.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_execute.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,14 +30,13 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.service_fabric_schedules.begin_execute( + client.service_fabric_schedules.begin_execute( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="@me", service_fabric_name="{serviceFrabicName}", name="{scheduleName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/ServiceFabricSchedules_Execute.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_get.py index 020828ac2bf1..ae6167863337 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_list.py index 2880f5255e2f..11d3ba17987d 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_update.py index 7ea8fc1bf546..e70ba1ad26ba 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabric_schedules_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_create_or_update.py index 54def811f813..f11515cb8bf1 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_delete.py index d8557dddff2a..2867a5e310dc 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.service_fabrics.begin_delete( + client.service_fabrics.begin_delete( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="{userName}", name="{serviceFabricName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/ServiceFabrics_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_get.py index 33478a50a719..cdb9fc09a64d 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_list.py index 70be57c20082..155cb59221b6 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_list_applicable_schedules.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_list_applicable_schedules.py index 89934ab0ea2b..08bd38746567 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_list_applicable_schedules.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_list_applicable_schedules.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_start.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_start.py index c3c859b5e9c7..3708d8e70440 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_start.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_start.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.service_fabrics.begin_start( + client.service_fabrics.begin_start( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="{userName}", name="{serviceFabricName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/ServiceFabrics_Start.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_stop.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_stop.py index a63563ac0709..6b9b9b1a41c1 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_stop.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_stop.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.service_fabrics.begin_stop( + client.service_fabrics.begin_stop( resource_group_name="resourceGroupName", lab_name="{labName}", user_name="{userName}", name="{serviceFabricName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/ServiceFabrics_Stop.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_update.py index af19351ec3ee..ddb71b3b5672 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_fabrics_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_create_or_update.py index 53d80774ed5b..0b73c602899e 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_delete.py index 591754c62ade..6c559acccd99 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.service_runners.delete( + client.service_runners.delete( resource_group_name="resourceGroupName", lab_name="{devtestlabName}", name="{servicerunnerName}", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/ServiceRunners_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_get.py index 788c31a9a768..2630cdb563e2 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/service_runners_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_create_or_update.py index 8cf033b1d5e2..ba6cdc718839 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_delete.py index 8ec0493be0fa..1ff98df2c7de 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.users.begin_delete( + client.users.begin_delete( resource_group_name="resourceGroupName", lab_name="{devtestlabName}", name="{userName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/Users_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_get.py index a84c50355976..50a879e77343 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_list.py index 4433f3069ca1..c859f6e87665 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_update.py index 5ca72d9a7841..b894b8b770c1 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/users_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_create_or_update.py index 52126fc43bf0..e8b3d768d8bc 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_delete.py index f0eb158ef93a..faf0ecd5f261 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machine_schedules.delete( + client.virtual_machine_schedules.delete( resource_group_name="resourceGroupName", lab_name="{labName}", virtual_machine_name="{vmName}", name="LabVmsShutdown", ) - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachineSchedules_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_execute.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_execute.py index 12cb06d6fdf3..0ba12bb8a096 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_execute.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_execute.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,13 +30,12 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machine_schedules.begin_execute( + client.virtual_machine_schedules.begin_execute( resource_group_name="resourceGroupName", lab_name="{labName}", virtual_machine_name="{vmName}", name="LabVmsShutdown", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachineSchedules_Execute.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_get.py index 5f6a66e34393..efb834fc0394 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_list.py index 1acd0ff9ba76..33a8d8bd49ea 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_update.py index d7584add1fec..07b92f47a508 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machine_schedules_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_add_data_disk.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_add_data_disk.py index aefdfdfe3dcc..2ff04d012e68 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_add_data_disk.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_add_data_disk.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,7 +30,7 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_add_data_disk( + client.virtual_machines.begin_add_data_disk( resource_group_name="resourceGroupName", lab_name="{labName}", name="{virtualMachineName}", @@ -37,7 +38,6 @@ def main(): "attachNewDataDiskOptions": {"diskName": "{diskName}", "diskSizeGiB": 127, "diskType": "{diskType}"} }, ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_AddDataDisk.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_apply_artifacts.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_apply_artifacts.py index 9c53ef217113..1fbc59582520 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_apply_artifacts.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_apply_artifacts.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_apply_artifacts( + client.virtual_machines.begin_apply_artifacts( resource_group_name="resourceGroupName", lab_name="{labName}", name="{vmName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_ApplyArtifacts.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_claim.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_claim.py index 493beae4a7fb..8c9f3b9639d9 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_claim.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_claim.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_claim( + client.virtual_machines.begin_claim( resource_group_name="resourceGroupName", lab_name="{labName}", name="{vmName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_Claim.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_create_or_update.py index 8998af79465b..7a4ef5f3bc86 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_delete.py index 94ad965b8643..ae3b24dcce52 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_delete( + client.virtual_machines.begin_delete( resource_group_name="resourceGroupName", lab_name="{labName}", name="{vmName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_detach_data_disk.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_detach_data_disk.py index 6c68d9ce9984..adef687806e6 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_detach_data_disk.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_detach_data_disk.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_detach_data_disk( + client.virtual_machines.begin_detach_data_disk( resource_group_name="resourceGroupName", lab_name="{labName}", name="{virtualMachineName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_DetachDataDisk.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_get.py index 0bd113716f40..698cf05e9ffa 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_get_rdp_file_contents.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_get_rdp_file_contents.py index 4b0442bb327e..0202aa89acea 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_get_rdp_file_contents.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_get_rdp_file_contents.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_list.py index 426e7971fcfa..000a6bb98e90 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_list_applicable_schedules.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_list_applicable_schedules.py index dee44204621f..cf7cfdf65782 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_list_applicable_schedules.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_list_applicable_schedules.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_redeploy.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_redeploy.py index faf420e67364..88a001a84fca 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_redeploy.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_redeploy.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_redeploy( + client.virtual_machines.begin_redeploy( resource_group_name="resourceGroupName", lab_name="{labName}", name="{vmName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_Redeploy.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_resize.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_resize.py index f2cf92b543a2..f5e25c4773f4 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_resize.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_resize.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_resize( + client.virtual_machines.begin_resize( resource_group_name="resourceGroupName", lab_name="{labName}", name="{vmName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_Resize.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_restart.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_restart.py index fb876e0aa206..64b319bc4800 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_restart.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_restart.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_restart( + client.virtual_machines.begin_restart( resource_group_name="resourceGroupName", lab_name="{labName}", name="{vmName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_Restart.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_start.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_start.py index 6993bd442704..2a153fd060c5 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_start.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_start.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_start( + client.virtual_machines.begin_start( resource_group_name="resourceGroupName", lab_name="{labName}", name="{vmName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_Start.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_stop.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_stop.py index a0b4a9e74312..0d920a240845 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_stop.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_stop.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_stop( + client.virtual_machines.begin_stop( resource_group_name="resourceGroupName", lab_name="{labName}", name="{vmName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_Stop.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_transfer_disks.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_transfer_disks.py index 3213670c8d9d..d982d3db770b 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_transfer_disks.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_transfer_disks.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_transfer_disks( + client.virtual_machines.begin_transfer_disks( resource_group_name="resourceGroupName", lab_name="{labName}", name="{virtualmachineName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_TransferDisks.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_un_claim.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_un_claim.py index 864992391a45..83b6181bdc53 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_un_claim.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_un_claim.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_machines.begin_un_claim( + client.virtual_machines.begin_un_claim( resource_group_name="resourceGroupName", lab_name="{labName}", name="{vmName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualMachines_UnClaim.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_update.py index 23b54273caab..eb89eb1fdfae 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_machines_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_create_or_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_create_or_update.py index dcb9c77f75c7..360e7a5cce57 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_create_or_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_create_or_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_delete.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_delete.py index 8aefd1303feb..078f97cf14c7 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_delete.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_delete.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ @@ -29,12 +30,11 @@ def main(): subscription_id="{subscriptionId}", ) - response = client.virtual_networks.begin_delete( + client.virtual_networks.begin_delete( resource_group_name="resourceGroupName", lab_name="{labName}", name="{virtualNetworkName}", ).result() - print(response) # x-ms-original-file: specification/devtestlabs/resource-manager/Microsoft.DevTestLab/stable/2018-09-15/examples/VirtualNetworks_Delete.json diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_get.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_get.py index 9145edb82d6b..80d26917a7af 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_get.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_get.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_list.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_list.py index 28b50d51455a..d394160aeeb9 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_list.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_list.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_update.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_update.py index 446844300efd..e431678c4752 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_update.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_samples/virtual_networks_update.py @@ -7,6 +7,7 @@ # -------------------------------------------------------------------------- from azure.identity import DefaultAzureCredential + from azure.mgmt.devtestlabs import DevTestLabsClient """ diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/conftest.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/conftest.py new file mode 100644 index 000000000000..4e3819d2abd2 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/conftest.py @@ -0,0 +1,35 @@ +# 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 os +import pytest +from dotenv import load_dotenv +from devtools_testutils import ( + test_proxy, + add_general_regex_sanitizer, + add_body_key_sanitizer, + add_header_regex_sanitizer, +) + +load_dotenv() + + +# aovid record sensitive identity information in recordings +@pytest.fixture(scope="session", autouse=True) +def add_sanitizers(test_proxy): + devtestlabs_subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + devtestlabs_tenant_id = os.environ.get("AZURE_TENANT_ID", "00000000-0000-0000-0000-000000000000") + devtestlabs_client_id = os.environ.get("AZURE_CLIENT_ID", "00000000-0000-0000-0000-000000000000") + devtestlabs_client_secret = os.environ.get("AZURE_CLIENT_SECRET", "00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=devtestlabs_subscription_id, value="00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=devtestlabs_tenant_id, value="00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=devtestlabs_client_id, value="00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=devtestlabs_client_secret, value="00000000-0000-0000-0000-000000000000") + + add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]") + add_header_regex_sanitizer(key="Cookie", value="cookie;") + add_body_key_sanitizer(json_path="$..access_token", value="access_token") diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_arm_templates_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_arm_templates_operations.py new file mode 100644 index 000000000000..726caecd06f5 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_arm_templates_operations.py @@ -0,0 +1,46 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsArmTemplatesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.arm_templates.list( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.arm_templates.get( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_arm_templates_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_arm_templates_operations_async.py new file mode 100644 index 000000000000..1ec633a42d0a --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_arm_templates_operations_async.py @@ -0,0 +1,47 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsArmTemplatesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.arm_templates.list( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.arm_templates.get( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifact_sources_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifact_sources_operations.py new file mode 100644 index 000000000000..41fc556bb570 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifact_sources_operations.py @@ -0,0 +1,101 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsArtifactSourcesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.artifact_sources.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.artifact_sources.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_create_or_update(self, resource_group): + response = self.client.artifact_sources.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + artifact_source={ + "armTemplateFolderPath": "str", + "branchRef": "str", + "createdDate": "2020-02-20 00:00:00", + "displayName": "str", + "folderPath": "str", + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "securityToken": "str", + "sourceType": "str", + "status": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "uri": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.artifact_sources.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.artifact_sources.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifact_sources_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifact_sources_operations_async.py new file mode 100644 index 000000000000..6d8b5fef7000 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifact_sources_operations_async.py @@ -0,0 +1,102 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsArtifactSourcesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.artifact_sources.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.artifact_sources.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_create_or_update(self, resource_group): + response = await self.client.artifact_sources.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + artifact_source={ + "armTemplateFolderPath": "str", + "branchRef": "str", + "createdDate": "2020-02-20 00:00:00", + "displayName": "str", + "folderPath": "str", + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "securityToken": "str", + "sourceType": "str", + "status": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "uri": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.artifact_sources.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.artifact_sources.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifacts_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifacts_operations.py new file mode 100644 index 000000000000..bc14afc415b0 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifacts_operations.py @@ -0,0 +1,66 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsArtifactsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.artifacts.list( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.artifacts.get( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_generate_arm_template(self, resource_group): + response = self.client.artifacts.generate_arm_template( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + name="str", + generate_arm_template_request={ + "fileUploadOptions": "str", + "location": "str", + "parameters": [{"name": "str", "value": "str"}], + "virtualMachineName": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifacts_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifacts_operations_async.py new file mode 100644 index 000000000000..88b89c350a47 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_artifacts_operations_async.py @@ -0,0 +1,67 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsArtifactsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.artifacts.list( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.artifacts.get( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_generate_arm_template(self, resource_group): + response = await self.client.artifacts.generate_arm_template( + resource_group_name=resource_group.name, + lab_name="str", + artifact_source_name="str", + name="str", + generate_arm_template_request={ + "fileUploadOptions": "str", + "location": "str", + "parameters": [{"name": "str", "value": "str"}], + "virtualMachineName": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_costs_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_costs_operations.py new file mode 100644 index 000000000000..387d01e810f1 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_costs_operations.py @@ -0,0 +1,89 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsCostsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.costs.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_create_or_update(self, resource_group): + response = self.client.costs.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + lab_cost={ + "createdDate": "2020-02-20 00:00:00", + "currencyCode": "str", + "endDateTime": "2020-02-20 00:00:00", + "id": "str", + "labCostDetails": [{"cost": 0.0, "costType": "str", "date": "2020-02-20 00:00:00"}], + "labCostSummary": {"estimatedLabCost": 0.0}, + "location": "str", + "name": "str", + "provisioningState": "str", + "resourceCosts": [ + { + "externalResourceId": "str", + "resourceCost": 0.0, + "resourceId": "str", + "resourceOwner": "str", + "resourcePricingTier": "str", + "resourceStatus": "str", + "resourceType": "str", + "resourceUId": "str", + "resourcename": "str", + } + ], + "startDateTime": "2020-02-20 00:00:00", + "tags": {"str": "str"}, + "targetCost": { + "costThresholds": [ + { + "displayOnChart": "str", + "notificationSent": "str", + "percentageThreshold": {"thresholdValue": 0.0}, + "sendNotificationWhenExceeded": "str", + "thresholdId": "str", + } + ], + "cycleEndDateTime": "2020-02-20 00:00:00", + "cycleStartDateTime": "2020-02-20 00:00:00", + "cycleType": "str", + "status": "str", + "target": 0, + }, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_costs_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_costs_operations_async.py new file mode 100644 index 000000000000..310d15439fe0 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_costs_operations_async.py @@ -0,0 +1,90 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsCostsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.costs.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_create_or_update(self, resource_group): + response = await self.client.costs.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + lab_cost={ + "createdDate": "2020-02-20 00:00:00", + "currencyCode": "str", + "endDateTime": "2020-02-20 00:00:00", + "id": "str", + "labCostDetails": [{"cost": 0.0, "costType": "str", "date": "2020-02-20 00:00:00"}], + "labCostSummary": {"estimatedLabCost": 0.0}, + "location": "str", + "name": "str", + "provisioningState": "str", + "resourceCosts": [ + { + "externalResourceId": "str", + "resourceCost": 0.0, + "resourceId": "str", + "resourceOwner": "str", + "resourcePricingTier": "str", + "resourceStatus": "str", + "resourceType": "str", + "resourceUId": "str", + "resourcename": "str", + } + ], + "startDateTime": "2020-02-20 00:00:00", + "tags": {"str": "str"}, + "targetCost": { + "costThresholds": [ + { + "displayOnChart": "str", + "notificationSent": "str", + "percentageThreshold": {"thresholdValue": 0.0}, + "sendNotificationWhenExceeded": "str", + "thresholdId": "str", + } + ], + "cycleEndDateTime": "2020-02-20 00:00:00", + "cycleStartDateTime": "2020-02-20 00:00:00", + "cycleType": "str", + "status": "str", + "target": 0, + }, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_custom_images_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_custom_images_operations.py new file mode 100644 index 000000000000..8c4144707906 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_custom_images_operations.py @@ -0,0 +1,106 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsCustomImagesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.custom_images.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.custom_images.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.custom_images.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + custom_image={ + "author": "str", + "creationDate": "2020-02-20 00:00:00", + "customImagePlan": {"id": "str", "offer": "str", "publisher": "str"}, + "dataDiskStorageInfo": [{"lun": "str", "storageType": "str"}], + "description": "str", + "id": "str", + "isPlanAuthorized": bool, + "location": "str", + "managedImageId": "str", + "managedSnapshotId": "str", + "name": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "vhd": {"osType": "str", "imageName": "str", "sysPrep": bool}, + "vm": { + "linuxOsInfo": {"linuxOsState": "str"}, + "sourceVmId": "str", + "windowsOsInfo": {"windowsOsState": "str"}, + }, + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.custom_images.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.custom_images.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_custom_images_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_custom_images_operations_async.py new file mode 100644 index 000000000000..de41d638ba5d --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_custom_images_operations_async.py @@ -0,0 +1,111 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsCustomImagesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.custom_images.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.custom_images.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.custom_images.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + custom_image={ + "author": "str", + "creationDate": "2020-02-20 00:00:00", + "customImagePlan": {"id": "str", "offer": "str", "publisher": "str"}, + "dataDiskStorageInfo": [{"lun": "str", "storageType": "str"}], + "description": "str", + "id": "str", + "isPlanAuthorized": bool, + "location": "str", + "managedImageId": "str", + "managedSnapshotId": "str", + "name": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "vhd": {"osType": "str", "imageName": "str", "sysPrep": bool}, + "vm": { + "linuxOsInfo": {"linuxOsState": "str"}, + "sourceVmId": "str", + "windowsOsInfo": {"windowsOsState": "str"}, + }, + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.custom_images.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.custom_images.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_disks_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_disks_operations.py new file mode 100644 index 000000000000..3b3ba2a5913c --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_disks_operations.py @@ -0,0 +1,134 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsDisksOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.disks.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.disks.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.disks.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + disk={ + "createdDate": "2020-02-20 00:00:00", + "diskBlobName": "str", + "diskSizeGiB": 0, + "diskType": "str", + "diskUri": "str", + "hostCaching": "str", + "id": "str", + "leasedByLabVmId": "str", + "location": "str", + "managedDiskId": "str", + "name": "str", + "provisioningState": "str", + "storageAccountId": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.disks.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.disks.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_attach(self, resource_group): + response = self.client.disks.begin_attach( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_detach(self, resource_group): + response = self.client.disks.begin_detach( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_disks_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_disks_operations_async.py new file mode 100644 index 000000000000..a9fa2a7cf35a --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_disks_operations_async.py @@ -0,0 +1,143 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsDisksOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.disks.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.disks.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.disks.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + disk={ + "createdDate": "2020-02-20 00:00:00", + "diskBlobName": "str", + "diskSizeGiB": 0, + "diskType": "str", + "diskUri": "str", + "hostCaching": "str", + "id": "str", + "leasedByLabVmId": "str", + "location": "str", + "managedDiskId": "str", + "name": "str", + "provisioningState": "str", + "storageAccountId": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.disks.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.disks.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_attach(self, resource_group): + response = await ( + await self.client.disks.begin_attach( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_detach(self, resource_group): + response = await ( + await self.client.disks.begin_detach( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_environments_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_environments_operations.py new file mode 100644 index 000000000000..bd42ac20b457 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_environments_operations.py @@ -0,0 +1,101 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsEnvironmentsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.environments.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.environments.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.environments.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + dtl_environment={ + "armTemplateDisplayName": "str", + "createdByUser": "str", + "deploymentProperties": {"armTemplateId": "str", "parameters": [{"name": "str", "value": "str"}]}, + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "resourceGroupId": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.environments.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.environments.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_environments_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_environments_operations_async.py new file mode 100644 index 000000000000..f5d58cf3de57 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_environments_operations_async.py @@ -0,0 +1,106 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsEnvironmentsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.environments.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.environments.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.environments.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + dtl_environment={ + "armTemplateDisplayName": "str", + "createdByUser": "str", + "deploymentProperties": {"armTemplateId": "str", "parameters": [{"name": "str", "value": "str"}]}, + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "resourceGroupId": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.environments.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.environments.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_formulas_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_formulas_operations.py new file mode 100644 index 000000000000..397dd2039662 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_formulas_operations.py @@ -0,0 +1,180 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsFormulasOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.formulas.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.formulas.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.formulas.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + formula={ + "author": "str", + "creationDate": "2020-02-20 00:00:00", + "description": "str", + "formulaContent": { + "allowClaim": False, + "artifacts": [ + { + "artifactId": "str", + "artifactTitle": "str", + "deploymentStatusMessage": "str", + "installTime": "2020-02-20 00:00:00", + "parameters": [{"name": "str", "value": "str"}], + "status": "str", + "vmExtensionStatusMessage": "str", + } + ], + "bulkCreationParameters": {"instanceCount": 0}, + "createdDate": "2020-02-20 00:00:00", + "customImageId": "str", + "dataDiskParameters": [ + { + "attachNewDataDiskOptions": {"diskName": "str", "diskSizeGiB": 0, "diskType": "str"}, + "existingLabDiskId": "str", + "hostCaching": "str", + } + ], + "disallowPublicIpAddress": False, + "environmentId": "str", + "expirationDate": "2020-02-20 00:00:00", + "galleryImageReference": { + "offer": "str", + "osType": "str", + "publisher": "str", + "sku": "str", + "version": "str", + }, + "isAuthenticationWithSshKey": bool, + "labSubnetName": "str", + "labVirtualNetworkId": "str", + "location": "str", + "name": "str", + "networkInterface": { + "dnsName": "str", + "privateIpAddress": "str", + "publicIpAddress": "str", + "publicIpAddressId": "str", + "rdpAuthority": "str", + "sharedPublicIpAddressConfiguration": { + "inboundNatRules": [{"backendPort": 0, "frontendPort": 0, "transportProtocol": "str"}] + }, + "sshAuthority": "str", + "subnetId": "str", + "virtualNetworkId": "str", + }, + "notes": "str", + "ownerObjectId": "dynamicValue", + "ownerUserPrincipalName": "str", + "password": "str", + "planId": "str", + "scheduleParameters": [ + { + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + } + ], + "size": "str", + "sshKey": "str", + "storageType": "labStorageType", + "tags": {"str": "str"}, + "userName": "str", + }, + "id": "str", + "location": "str", + "name": "str", + "osType": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "vm": {"labVmId": "str"}, + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.formulas.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.formulas.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_formulas_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_formulas_operations_async.py new file mode 100644 index 000000000000..018abdb72a11 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_formulas_operations_async.py @@ -0,0 +1,183 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsFormulasOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.formulas.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.formulas.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.formulas.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + formula={ + "author": "str", + "creationDate": "2020-02-20 00:00:00", + "description": "str", + "formulaContent": { + "allowClaim": False, + "artifacts": [ + { + "artifactId": "str", + "artifactTitle": "str", + "deploymentStatusMessage": "str", + "installTime": "2020-02-20 00:00:00", + "parameters": [{"name": "str", "value": "str"}], + "status": "str", + "vmExtensionStatusMessage": "str", + } + ], + "bulkCreationParameters": {"instanceCount": 0}, + "createdDate": "2020-02-20 00:00:00", + "customImageId": "str", + "dataDiskParameters": [ + { + "attachNewDataDiskOptions": {"diskName": "str", "diskSizeGiB": 0, "diskType": "str"}, + "existingLabDiskId": "str", + "hostCaching": "str", + } + ], + "disallowPublicIpAddress": False, + "environmentId": "str", + "expirationDate": "2020-02-20 00:00:00", + "galleryImageReference": { + "offer": "str", + "osType": "str", + "publisher": "str", + "sku": "str", + "version": "str", + }, + "isAuthenticationWithSshKey": bool, + "labSubnetName": "str", + "labVirtualNetworkId": "str", + "location": "str", + "name": "str", + "networkInterface": { + "dnsName": "str", + "privateIpAddress": "str", + "publicIpAddress": "str", + "publicIpAddressId": "str", + "rdpAuthority": "str", + "sharedPublicIpAddressConfiguration": { + "inboundNatRules": [{"backendPort": 0, "frontendPort": 0, "transportProtocol": "str"}] + }, + "sshAuthority": "str", + "subnetId": "str", + "virtualNetworkId": "str", + }, + "notes": "str", + "ownerObjectId": "dynamicValue", + "ownerUserPrincipalName": "str", + "password": "str", + "planId": "str", + "scheduleParameters": [ + { + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + } + ], + "size": "str", + "sshKey": "str", + "storageType": "labStorageType", + "tags": {"str": "str"}, + "userName": "str", + }, + "id": "str", + "location": "str", + "name": "str", + "osType": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "vm": {"labVmId": "str"}, + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.formulas.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.formulas.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_gallery_images_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_gallery_images_operations.py new file mode 100644 index 000000000000..e598b6655f4e --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_gallery_images_operations.py @@ -0,0 +1,31 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsGalleryImagesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.gallery_images.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_gallery_images_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_gallery_images_operations_async.py new file mode 100644 index 000000000000..36d04af15102 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_gallery_images_operations_async.py @@ -0,0 +1,32 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsGalleryImagesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.gallery_images.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_global_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_global_schedules_operations.py new file mode 100644 index 000000000000..544bada2770c --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_global_schedules_operations.py @@ -0,0 +1,136 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsGlobalSchedulesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_subscription(self, resource_group): + response = self.client.global_schedules.list_by_subscription( + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_resource_group(self, resource_group): + response = self.client.global_schedules.list_by_resource_group( + resource_group_name=resource_group.name, + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.global_schedules.get( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_create_or_update(self, resource_group): + response = self.client.global_schedules.create_or_update( + resource_group_name=resource_group.name, + name="str", + schedule={ + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.global_schedules.delete( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.global_schedules.update( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_execute(self, resource_group): + response = self.client.global_schedules.begin_execute( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_retarget(self, resource_group): + response = self.client.global_schedules.begin_retarget( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_global_schedules_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_global_schedules_operations_async.py new file mode 100644 index 000000000000..95123b48f015 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_global_schedules_operations_async.py @@ -0,0 +1,141 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsGlobalSchedulesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_subscription(self, resource_group): + response = self.client.global_schedules.list_by_subscription( + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_resource_group(self, resource_group): + response = self.client.global_schedules.list_by_resource_group( + resource_group_name=resource_group.name, + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.global_schedules.get( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_create_or_update(self, resource_group): + response = await self.client.global_schedules.create_or_update( + resource_group_name=resource_group.name, + name="str", + schedule={ + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.global_schedules.delete( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.global_schedules.update( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_execute(self, resource_group): + response = await ( + await self.client.global_schedules.begin_execute( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_retarget(self, resource_group): + response = await ( + await self.client.global_schedules.begin_retarget( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_labs_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_labs_operations.py new file mode 100644 index 000000000000..ff283c1d35bc --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_labs_operations.py @@ -0,0 +1,278 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsLabsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_subscription(self, resource_group): + response = self.client.labs.list_by_subscription( + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_resource_group(self, resource_group): + response = self.client.labs.list_by_resource_group( + resource_group_name=resource_group.name, + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.labs.get( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.labs.begin_create_or_update( + resource_group_name=resource_group.name, + name="str", + lab={ + "announcement": { + "enabled": "str", + "expirationDate": "2020-02-20 00:00:00", + "expired": bool, + "markdown": "str", + "provisioningState": "str", + "title": "str", + "uniqueIdentifier": "str", + }, + "artifactsStorageAccount": "str", + "createdDate": "2020-02-20 00:00:00", + "defaultPremiumStorageAccount": "str", + "defaultStorageAccount": "str", + "environmentPermission": "str", + "extendedProperties": {"str": "str"}, + "id": "str", + "labStorageType": "str", + "loadBalancerId": "str", + "location": "str", + "mandatoryArtifactsResourceIdsLinux": ["str"], + "mandatoryArtifactsResourceIdsWindows": ["str"], + "name": "str", + "networkSecurityGroupId": "str", + "premiumDataDiskStorageAccount": "str", + "premiumDataDisks": "str", + "provisioningState": "str", + "publicIpId": "str", + "support": {"enabled": "str", "markdown": "str"}, + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "vaultName": "str", + "vmCreationResourceGroup": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.labs.begin_delete( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.labs.update( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_claim_any_vm(self, resource_group): + response = self.client.labs.begin_claim_any_vm( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_environment(self, resource_group): + response = self.client.labs.begin_create_environment( + resource_group_name=resource_group.name, + name="str", + lab_virtual_machine_creation_parameter={ + "allowClaim": False, + "artifacts": [ + { + "artifactId": "str", + "artifactTitle": "str", + "deploymentStatusMessage": "str", + "installTime": "2020-02-20 00:00:00", + "parameters": [{"name": "str", "value": "str"}], + "status": "str", + "vmExtensionStatusMessage": "str", + } + ], + "bulkCreationParameters": {"instanceCount": 0}, + "createdDate": "2020-02-20 00:00:00", + "customImageId": "str", + "dataDiskParameters": [ + { + "attachNewDataDiskOptions": {"diskName": "str", "diskSizeGiB": 0, "diskType": "str"}, + "existingLabDiskId": "str", + "hostCaching": "str", + } + ], + "disallowPublicIpAddress": False, + "environmentId": "str", + "expirationDate": "2020-02-20 00:00:00", + "galleryImageReference": { + "offer": "str", + "osType": "str", + "publisher": "str", + "sku": "str", + "version": "str", + }, + "isAuthenticationWithSshKey": bool, + "labSubnetName": "str", + "labVirtualNetworkId": "str", + "location": "str", + "name": "str", + "networkInterface": { + "dnsName": "str", + "privateIpAddress": "str", + "publicIpAddress": "str", + "publicIpAddressId": "str", + "rdpAuthority": "str", + "sharedPublicIpAddressConfiguration": { + "inboundNatRules": [{"backendPort": 0, "frontendPort": 0, "transportProtocol": "str"}] + }, + "sshAuthority": "str", + "subnetId": "str", + "virtualNetworkId": "str", + }, + "notes": "str", + "ownerObjectId": "dynamicValue", + "ownerUserPrincipalName": "str", + "password": "str", + "planId": "str", + "scheduleParameters": [ + { + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + } + ], + "size": "str", + "sshKey": "str", + "storageType": "labStorageType", + "tags": {"str": "str"}, + "userName": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_export_resource_usage(self, resource_group): + response = self.client.labs.begin_export_resource_usage( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_generate_upload_uri(self, resource_group): + response = self.client.labs.generate_upload_uri( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_import_virtual_machine(self, resource_group): + response = self.client.labs.begin_import_virtual_machine( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_vhds(self, resource_group): + response = self.client.labs.list_vhds( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_labs_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_labs_operations_async.py new file mode 100644 index 000000000000..dedfbd0c2bbc --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_labs_operations_async.py @@ -0,0 +1,291 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsLabsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_subscription(self, resource_group): + response = self.client.labs.list_by_subscription( + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_resource_group(self, resource_group): + response = self.client.labs.list_by_resource_group( + resource_group_name=resource_group.name, + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.labs.get( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.labs.begin_create_or_update( + resource_group_name=resource_group.name, + name="str", + lab={ + "announcement": { + "enabled": "str", + "expirationDate": "2020-02-20 00:00:00", + "expired": bool, + "markdown": "str", + "provisioningState": "str", + "title": "str", + "uniqueIdentifier": "str", + }, + "artifactsStorageAccount": "str", + "createdDate": "2020-02-20 00:00:00", + "defaultPremiumStorageAccount": "str", + "defaultStorageAccount": "str", + "environmentPermission": "str", + "extendedProperties": {"str": "str"}, + "id": "str", + "labStorageType": "str", + "loadBalancerId": "str", + "location": "str", + "mandatoryArtifactsResourceIdsLinux": ["str"], + "mandatoryArtifactsResourceIdsWindows": ["str"], + "name": "str", + "networkSecurityGroupId": "str", + "premiumDataDiskStorageAccount": "str", + "premiumDataDisks": "str", + "provisioningState": "str", + "publicIpId": "str", + "support": {"enabled": "str", "markdown": "str"}, + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "vaultName": "str", + "vmCreationResourceGroup": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.labs.begin_delete( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.labs.update( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_claim_any_vm(self, resource_group): + response = await ( + await self.client.labs.begin_claim_any_vm( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_environment(self, resource_group): + response = await ( + await self.client.labs.begin_create_environment( + resource_group_name=resource_group.name, + name="str", + lab_virtual_machine_creation_parameter={ + "allowClaim": False, + "artifacts": [ + { + "artifactId": "str", + "artifactTitle": "str", + "deploymentStatusMessage": "str", + "installTime": "2020-02-20 00:00:00", + "parameters": [{"name": "str", "value": "str"}], + "status": "str", + "vmExtensionStatusMessage": "str", + } + ], + "bulkCreationParameters": {"instanceCount": 0}, + "createdDate": "2020-02-20 00:00:00", + "customImageId": "str", + "dataDiskParameters": [ + { + "attachNewDataDiskOptions": {"diskName": "str", "diskSizeGiB": 0, "diskType": "str"}, + "existingLabDiskId": "str", + "hostCaching": "str", + } + ], + "disallowPublicIpAddress": False, + "environmentId": "str", + "expirationDate": "2020-02-20 00:00:00", + "galleryImageReference": { + "offer": "str", + "osType": "str", + "publisher": "str", + "sku": "str", + "version": "str", + }, + "isAuthenticationWithSshKey": bool, + "labSubnetName": "str", + "labVirtualNetworkId": "str", + "location": "str", + "name": "str", + "networkInterface": { + "dnsName": "str", + "privateIpAddress": "str", + "publicIpAddress": "str", + "publicIpAddressId": "str", + "rdpAuthority": "str", + "sharedPublicIpAddressConfiguration": { + "inboundNatRules": [{"backendPort": 0, "frontendPort": 0, "transportProtocol": "str"}] + }, + "sshAuthority": "str", + "subnetId": "str", + "virtualNetworkId": "str", + }, + "notes": "str", + "ownerObjectId": "dynamicValue", + "ownerUserPrincipalName": "str", + "password": "str", + "planId": "str", + "scheduleParameters": [ + { + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + } + ], + "size": "str", + "sshKey": "str", + "storageType": "labStorageType", + "tags": {"str": "str"}, + "userName": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_export_resource_usage(self, resource_group): + response = await ( + await self.client.labs.begin_export_resource_usage( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_generate_upload_uri(self, resource_group): + response = await self.client.labs.generate_upload_uri( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_import_virtual_machine(self, resource_group): + response = await ( + await self.client.labs.begin_import_virtual_machine( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_vhds(self, resource_group): + response = self.client.labs.list_vhds( + resource_group_name=resource_group.name, + name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_notification_channels_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_notification_channels_operations.py new file mode 100644 index 000000000000..d2832992daca --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_notification_channels_operations.py @@ -0,0 +1,111 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsNotificationChannelsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.notification_channels.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.notification_channels.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_create_or_update(self, resource_group): + response = self.client.notification_channels.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + notification_channel={ + "createdDate": "2020-02-20 00:00:00", + "description": "str", + "emailRecipient": "str", + "events": [{"eventName": "str"}], + "id": "str", + "location": "str", + "name": "str", + "notificationLocale": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "webHookUrl": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.notification_channels.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.notification_channels.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_notify(self, resource_group): + response = self.client.notification_channels.notify( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_notification_channels_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_notification_channels_operations_async.py new file mode 100644 index 000000000000..e15887f5e7e4 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_notification_channels_operations_async.py @@ -0,0 +1,112 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsNotificationChannelsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.notification_channels.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.notification_channels.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_create_or_update(self, resource_group): + response = await self.client.notification_channels.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + notification_channel={ + "createdDate": "2020-02-20 00:00:00", + "description": "str", + "emailRecipient": "str", + "events": [{"eventName": "str"}], + "id": "str", + "location": "str", + "name": "str", + "notificationLocale": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "webHookUrl": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.notification_channels.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.notification_channels.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_notify(self, resource_group): + response = await self.client.notification_channels.notify( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_operations.py new file mode 100644 index 000000000000..35f4e4623737 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_operations.py @@ -0,0 +1,31 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.operations.get( + location_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_operations_async.py new file mode 100644 index 000000000000..11a294c6dfbf --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_operations_async.py @@ -0,0 +1,32 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.operations.get( + location_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policies_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policies_operations.py new file mode 100644 index 000000000000..98768ba817be --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policies_operations.py @@ -0,0 +1,104 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsPoliciesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.policies.list( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.policies.get( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_create_or_update(self, resource_group): + response = self.client.policies.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + name="str", + policy={ + "createdDate": "2020-02-20 00:00:00", + "description": "str", + "evaluatorType": "str", + "factData": "str", + "factName": "str", + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "threshold": "str", + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.policies.delete( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.policies.update( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policies_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policies_operations_async.py new file mode 100644 index 000000000000..230bf6b09d77 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policies_operations_async.py @@ -0,0 +1,105 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsPoliciesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.policies.list( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.policies.get( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_create_or_update(self, resource_group): + response = await self.client.policies.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + name="str", + policy={ + "createdDate": "2020-02-20 00:00:00", + "description": "str", + "evaluatorType": "str", + "factData": "str", + "factName": "str", + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "threshold": "str", + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.policies.delete( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.policies.update( + resource_group_name=resource_group.name, + lab_name="str", + policy_set_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policy_sets_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policy_sets_operations.py new file mode 100644 index 000000000000..ea40cd501087 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policy_sets_operations.py @@ -0,0 +1,32 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsPolicySetsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_evaluate_policies(self, resource_group): + response = self.client.policy_sets.evaluate_policies( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policy_sets_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policy_sets_operations_async.py new file mode 100644 index 000000000000..97b936c1f204 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_policy_sets_operations_async.py @@ -0,0 +1,33 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsPolicySetsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_evaluate_policies(self, resource_group): + response = await self.client.policy_sets.evaluate_policies( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_provider_operations_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_provider_operations_operations.py new file mode 100644 index 000000000000..63bd09dbc874 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_provider_operations_operations.py @@ -0,0 +1,29 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsProviderOperationsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.provider_operations.list( + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_provider_operations_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_provider_operations_operations_async.py new file mode 100644 index 000000000000..155d2b6221a4 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_provider_operations_operations_async.py @@ -0,0 +1,30 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsProviderOperationsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.provider_operations.list( + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_schedules_operations.py new file mode 100644 index 000000000000..46e9b2e835fa --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_schedules_operations.py @@ -0,0 +1,133 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsSchedulesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.schedules.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.schedules.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_create_or_update(self, resource_group): + response = self.client.schedules.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + schedule={ + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.schedules.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.schedules.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_execute(self, resource_group): + response = self.client.schedules.begin_execute( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_applicable(self, resource_group): + response = self.client.schedules.list_applicable( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_schedules_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_schedules_operations_async.py new file mode 100644 index 000000000000..fadda5d74d03 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_schedules_operations_async.py @@ -0,0 +1,136 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsSchedulesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.schedules.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.schedules.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_create_or_update(self, resource_group): + response = await self.client.schedules.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + schedule={ + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.schedules.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.schedules.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_execute(self, resource_group): + response = await ( + await self.client.schedules.begin_execute( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_applicable(self, resource_group): + response = self.client.schedules.list_applicable( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_secrets_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_secrets_operations.py new file mode 100644 index 000000000000..4b93eb5272dd --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_secrets_operations.py @@ -0,0 +1,98 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsSecretsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.secrets.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.secrets.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.secrets.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + secret={ + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "value": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.secrets.delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.secrets.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_secrets_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_secrets_operations_async.py new file mode 100644 index 000000000000..9177bb52cb2a --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_secrets_operations_async.py @@ -0,0 +1,101 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsSecretsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.secrets.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.secrets.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.secrets.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + secret={ + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "value": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.secrets.delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.secrets.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabric_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabric_schedules_operations.py new file mode 100644 index 000000000000..a1b94b5f4102 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabric_schedules_operations.py @@ -0,0 +1,132 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsServiceFabricSchedulesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.service_fabric_schedules.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.service_fabric_schedules.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_create_or_update(self, resource_group): + response = self.client.service_fabric_schedules.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + schedule={ + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.service_fabric_schedules.delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.service_fabric_schedules.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_execute(self, resource_group): + response = self.client.service_fabric_schedules.begin_execute( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabric_schedules_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabric_schedules_operations_async.py new file mode 100644 index 000000000000..120ddb9c13e7 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabric_schedules_operations_async.py @@ -0,0 +1,135 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsServiceFabricSchedulesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.service_fabric_schedules.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.service_fabric_schedules.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_create_or_update(self, resource_group): + response = await self.client.service_fabric_schedules.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + schedule={ + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.service_fabric_schedules.delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.service_fabric_schedules.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_execute(self, resource_group): + response = await ( + await self.client.service_fabric_schedules.begin_execute( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + service_fabric_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabrics_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabrics_operations.py new file mode 100644 index 000000000000..a8fbff8ec465 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabrics_operations.py @@ -0,0 +1,196 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsServiceFabricsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.service_fabrics.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.service_fabrics.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.service_fabrics.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + service_fabric={ + "applicableSchedule": { + "id": "str", + "labVmsShutdown": { + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + "labVmsStartup": { + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + "location": "str", + "name": "str", + "tags": {"str": "str"}, + "type": "str", + }, + "environmentId": "str", + "externalServiceFabricId": "str", + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.service_fabrics.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.service_fabrics.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_applicable_schedules(self, resource_group): + response = self.client.service_fabrics.list_applicable_schedules( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_start(self, resource_group): + response = self.client.service_fabrics.begin_start( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_stop(self, resource_group): + response = self.client.service_fabrics.begin_stop( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabrics_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabrics_operations_async.py new file mode 100644 index 000000000000..60d7feb3c86f --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_fabrics_operations_async.py @@ -0,0 +1,205 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsServiceFabricsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.service_fabrics.list( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.service_fabrics.get( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.service_fabrics.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + service_fabric={ + "applicableSchedule": { + "id": "str", + "labVmsShutdown": { + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + "labVmsStartup": { + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + "location": "str", + "name": "str", + "tags": {"str": "str"}, + "type": "str", + }, + "environmentId": "str", + "externalServiceFabricId": "str", + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.service_fabrics.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.service_fabrics.update( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_applicable_schedules(self, resource_group): + response = await self.client.service_fabrics.list_applicable_schedules( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_start(self, resource_group): + response = await ( + await self.client.service_fabrics.begin_start( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_stop(self, resource_group): + response = await ( + await self.client.service_fabrics.begin_stop( + resource_group_name=resource_group.name, + lab_name="str", + user_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_runners_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_runners_operations.py new file mode 100644 index 000000000000..0505e80f4510 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_runners_operations.py @@ -0,0 +1,66 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsServiceRunnersOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.service_runners.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_create_or_update(self, resource_group): + response = self.client.service_runners.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + service_runner={ + "id": "str", + "identity": {"clientSecretUrl": "str", "principalId": "str", "tenantId": "str", "type": "str"}, + "location": "str", + "name": "str", + "tags": {"str": "str"}, + "type": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.service_runners.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_runners_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_runners_operations_async.py new file mode 100644 index 000000000000..c32c83fb8e60 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_service_runners_operations_async.py @@ -0,0 +1,67 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsServiceRunnersOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.service_runners.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_create_or_update(self, resource_group): + response = await self.client.service_runners.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + service_runner={ + "id": "str", + "identity": {"clientSecretUrl": "str", "principalId": "str", "tenantId": "str", "type": "str"}, + "location": "str", + "name": "str", + "tags": {"str": "str"}, + "type": "str", + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.service_runners.delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_users_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_users_operations.py new file mode 100644 index 000000000000..b5701a9da430 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_users_operations.py @@ -0,0 +1,101 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsUsersOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.users.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.users.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.users.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + user={ + "createdDate": "2020-02-20 00:00:00", + "id": "str", + "identity": { + "appId": "str", + "objectId": "str", + "principalId": "str", + "principalName": "str", + "tenantId": "str", + }, + "location": "str", + "name": "str", + "provisioningState": "str", + "secretStore": {"keyVaultId": "str", "keyVaultUri": "str"}, + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.users.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.users.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_users_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_users_operations_async.py new file mode 100644 index 000000000000..05adfcaa9392 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_users_operations_async.py @@ -0,0 +1,106 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsUsersOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.users.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.users.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.users.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + user={ + "createdDate": "2020-02-20 00:00:00", + "id": "str", + "identity": { + "appId": "str", + "objectId": "str", + "principalId": "str", + "principalName": "str", + "tenantId": "str", + }, + "location": "str", + "name": "str", + "provisioningState": "str", + "secretStore": {"keyVaultId": "str", "keyVaultUri": "str"}, + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.users.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.users.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machine_schedules_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machine_schedules_operations.py new file mode 100644 index 000000000000..0ad396f107ac --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machine_schedules_operations.py @@ -0,0 +1,126 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsVirtualMachineSchedulesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.virtual_machine_schedules.list( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.virtual_machine_schedules.get( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_create_or_update(self, resource_group): + response = self.client.virtual_machine_schedules.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + schedule={ + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_delete(self, resource_group): + response = self.client.virtual_machine_schedules.delete( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.virtual_machine_schedules.update( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_execute(self, resource_group): + response = self.client.virtual_machine_schedules.begin_execute( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machine_schedules_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machine_schedules_operations_async.py new file mode 100644 index 000000000000..105d4cee1db8 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machine_schedules_operations_async.py @@ -0,0 +1,129 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsVirtualMachineSchedulesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.virtual_machine_schedules.list( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.virtual_machine_schedules.get( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_create_or_update(self, resource_group): + response = await self.client.virtual_machine_schedules.create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + schedule={ + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_delete(self, resource_group): + response = await self.client.virtual_machine_schedules.delete( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.virtual_machine_schedules.update( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_execute(self, resource_group): + response = await ( + await self.client.virtual_machine_schedules.begin_execute( + resource_group_name=resource_group.name, + lab_name="str", + virtual_machine_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machines_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machines_operations.py new file mode 100644 index 000000000000..32b555813fb2 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machines_operations.py @@ -0,0 +1,415 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsVirtualMachinesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.virtual_machines.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.virtual_machines.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.virtual_machines.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + lab_virtual_machine={ + "allowClaim": False, + "applicableSchedule": { + "id": "str", + "labVmsShutdown": { + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + "labVmsStartup": { + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + "location": "str", + "name": "str", + "tags": {"str": "str"}, + "type": "str", + }, + "artifactDeploymentStatus": {"artifactsApplied": 0, "deploymentStatus": "str", "totalArtifacts": 0}, + "artifacts": [ + { + "artifactId": "str", + "artifactTitle": "str", + "deploymentStatusMessage": "str", + "installTime": "2020-02-20 00:00:00", + "parameters": [{"name": "str", "value": "str"}], + "status": "str", + "vmExtensionStatusMessage": "str", + } + ], + "computeId": "str", + "computeVm": { + "dataDiskIds": ["str"], + "dataDisks": [{"diskSizeGiB": 0, "diskUri": "str", "managedDiskId": "str", "name": "str"}], + "networkInterfaceId": "str", + "osDiskId": "str", + "osType": "str", + "statuses": [{"code": "str", "displayStatus": "str", "message": "str"}], + "vmSize": "str", + }, + "createdByUser": "str", + "createdByUserId": "str", + "createdDate": "2020-02-20 00:00:00", + "customImageId": "str", + "dataDiskParameters": [ + { + "attachNewDataDiskOptions": {"diskName": "str", "diskSizeGiB": 0, "diskType": "str"}, + "existingLabDiskId": "str", + "hostCaching": "str", + } + ], + "disallowPublicIpAddress": False, + "environmentId": "str", + "expirationDate": "2020-02-20 00:00:00", + "fqdn": "str", + "galleryImageReference": { + "offer": "str", + "osType": "str", + "publisher": "str", + "sku": "str", + "version": "str", + }, + "id": "str", + "isAuthenticationWithSshKey": bool, + "labSubnetName": "str", + "labVirtualNetworkId": "str", + "lastKnownPowerState": "str", + "location": "str", + "name": "str", + "networkInterface": { + "dnsName": "str", + "privateIpAddress": "str", + "publicIpAddress": "str", + "publicIpAddressId": "str", + "rdpAuthority": "str", + "sharedPublicIpAddressConfiguration": { + "inboundNatRules": [{"backendPort": 0, "frontendPort": 0, "transportProtocol": "str"}] + }, + "sshAuthority": "str", + "subnetId": "str", + "virtualNetworkId": "str", + }, + "notes": "str", + "osType": "str", + "ownerObjectId": "dynamicValue", + "ownerUserPrincipalName": "str", + "password": "str", + "planId": "str", + "provisioningState": "str", + "scheduleParameters": [ + { + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + } + ], + "size": "str", + "sshKey": "str", + "storageType": "labStorageType", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "userName": "str", + "virtualMachineCreationSource": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.virtual_machines.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.virtual_machines.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_add_data_disk(self, resource_group): + response = self.client.virtual_machines.begin_add_data_disk( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + data_disk_properties={ + "attachNewDataDiskOptions": {"diskName": "str", "diskSizeGiB": 0, "diskType": "str"}, + "existingLabDiskId": "str", + "hostCaching": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_apply_artifacts(self, resource_group): + response = self.client.virtual_machines.begin_apply_artifacts( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_claim(self, resource_group): + response = self.client.virtual_machines.begin_claim( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_detach_data_disk(self, resource_group): + response = self.client.virtual_machines.begin_detach_data_disk( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get_rdp_file_contents(self, resource_group): + response = self.client.virtual_machines.get_rdp_file_contents( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_applicable_schedules(self, resource_group): + response = self.client.virtual_machines.list_applicable_schedules( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_redeploy(self, resource_group): + response = self.client.virtual_machines.begin_redeploy( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_resize(self, resource_group): + response = self.client.virtual_machines.begin_resize( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_restart(self, resource_group): + response = self.client.virtual_machines.begin_restart( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_start(self, resource_group): + response = self.client.virtual_machines.begin_start( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_stop(self, resource_group): + response = self.client.virtual_machines.begin_stop( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_transfer_disks(self, resource_group): + response = self.client.virtual_machines.begin_transfer_disks( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_un_claim(self, resource_group): + response = self.client.virtual_machines.begin_un_claim( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machines_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machines_operations_async.py new file mode 100644 index 000000000000..386c5627b1cd --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_machines_operations_async.py @@ -0,0 +1,442 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsVirtualMachinesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.virtual_machines.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.virtual_machines.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + lab_virtual_machine={ + "allowClaim": False, + "applicableSchedule": { + "id": "str", + "labVmsShutdown": { + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + "labVmsStartup": { + "createdDate": "2020-02-20 00:00:00", + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "id": "str", + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "provisioningState": "str", + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "type": "str", + "uniqueIdentifier": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + }, + "location": "str", + "name": "str", + "tags": {"str": "str"}, + "type": "str", + }, + "artifactDeploymentStatus": {"artifactsApplied": 0, "deploymentStatus": "str", "totalArtifacts": 0}, + "artifacts": [ + { + "artifactId": "str", + "artifactTitle": "str", + "deploymentStatusMessage": "str", + "installTime": "2020-02-20 00:00:00", + "parameters": [{"name": "str", "value": "str"}], + "status": "str", + "vmExtensionStatusMessage": "str", + } + ], + "computeId": "str", + "computeVm": { + "dataDiskIds": ["str"], + "dataDisks": [{"diskSizeGiB": 0, "diskUri": "str", "managedDiskId": "str", "name": "str"}], + "networkInterfaceId": "str", + "osDiskId": "str", + "osType": "str", + "statuses": [{"code": "str", "displayStatus": "str", "message": "str"}], + "vmSize": "str", + }, + "createdByUser": "str", + "createdByUserId": "str", + "createdDate": "2020-02-20 00:00:00", + "customImageId": "str", + "dataDiskParameters": [ + { + "attachNewDataDiskOptions": {"diskName": "str", "diskSizeGiB": 0, "diskType": "str"}, + "existingLabDiskId": "str", + "hostCaching": "str", + } + ], + "disallowPublicIpAddress": False, + "environmentId": "str", + "expirationDate": "2020-02-20 00:00:00", + "fqdn": "str", + "galleryImageReference": { + "offer": "str", + "osType": "str", + "publisher": "str", + "sku": "str", + "version": "str", + }, + "id": "str", + "isAuthenticationWithSshKey": bool, + "labSubnetName": "str", + "labVirtualNetworkId": "str", + "lastKnownPowerState": "str", + "location": "str", + "name": "str", + "networkInterface": { + "dnsName": "str", + "privateIpAddress": "str", + "publicIpAddress": "str", + "publicIpAddressId": "str", + "rdpAuthority": "str", + "sharedPublicIpAddressConfiguration": { + "inboundNatRules": [{"backendPort": 0, "frontendPort": 0, "transportProtocol": "str"}] + }, + "sshAuthority": "str", + "subnetId": "str", + "virtualNetworkId": "str", + }, + "notes": "str", + "osType": "str", + "ownerObjectId": "dynamicValue", + "ownerUserPrincipalName": "str", + "password": "str", + "planId": "str", + "provisioningState": "str", + "scheduleParameters": [ + { + "dailyRecurrence": {"time": "str"}, + "hourlyRecurrence": {"minute": 0}, + "location": "str", + "name": "str", + "notificationSettings": { + "emailRecipient": "str", + "notificationLocale": "str", + "status": "str", + "timeInMinutes": 0, + "webhookUrl": "str", + }, + "status": "str", + "tags": {"str": "str"}, + "targetResourceId": "str", + "taskType": "str", + "timeZoneId": "str", + "weeklyRecurrence": {"time": "str", "weekdays": ["str"]}, + } + ], + "size": "str", + "sshKey": "str", + "storageType": "labStorageType", + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + "userName": "str", + "virtualMachineCreationSource": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.virtual_machines.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_add_data_disk(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_add_data_disk( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + data_disk_properties={ + "attachNewDataDiskOptions": {"diskName": "str", "diskSizeGiB": 0, "diskType": "str"}, + "existingLabDiskId": "str", + "hostCaching": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_apply_artifacts(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_apply_artifacts( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_claim(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_claim( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_detach_data_disk(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_detach_data_disk( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get_rdp_file_contents(self, resource_group): + response = await self.client.virtual_machines.get_rdp_file_contents( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_applicable_schedules(self, resource_group): + response = await self.client.virtual_machines.list_applicable_schedules( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_redeploy(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_redeploy( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_resize(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_resize( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_restart(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_restart( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_start(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_start( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_stop(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_stop( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_transfer_disks(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_transfer_disks( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_un_claim(self, resource_group): + response = await ( + await self.client.virtual_machines.begin_un_claim( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_networks_operations.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_networks_operations.py new file mode 100644 index 000000000000..7ea9b9485580 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_networks_operations.py @@ -0,0 +1,109 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsVirtualNetworksOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.virtual_networks.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_get(self, resource_group): + response = self.client.virtual_networks.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_create_or_update(self, resource_group): + response = self.client.virtual_networks.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + virtual_network={ + "allowedSubnets": [{"allowPublicIp": "str", "labSubnetName": "str", "resourceId": "str"}], + "createdDate": "2020-02-20 00:00:00", + "description": "str", + "externalProviderResourceId": "str", + "externalSubnets": [{"id": "str", "name": "str"}], + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "subnetOverrides": [ + { + "labSubnetName": "str", + "resourceId": "str", + "sharedPublicIpAddressConfiguration": { + "allowedPorts": [{"backendPort": 0, "transportProtocol": "str"}] + }, + "useInVmCreationPermission": "str", + "usePublicIpAddressPermission": "str", + "virtualNetworkPoolName": "str", + } + ], + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_begin_delete(self, resource_group): + response = self.client.virtual_networks.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_update(self, resource_group): + response = self.client.virtual_networks.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_networks_operations_async.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_networks_operations_async.py new file mode 100644 index 000000000000..9c1ae6d83ce4 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/generated_tests/test_dev_test_labs_virtual_networks_operations_async.py @@ -0,0 +1,114 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.skip("you may need to update the auto-generated test case before run it") +class TestDevTestLabsVirtualNetworksOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.virtual_networks.list( + resource_group_name=resource_group.name, + lab_name="str", + api_version="2018-09-15", + ) + result = [r async for r in response] + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_get(self, resource_group): + response = await self.client.virtual_networks.get( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_create_or_update(self, resource_group): + response = await ( + await self.client.virtual_networks.begin_create_or_update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + virtual_network={ + "allowedSubnets": [{"allowPublicIp": "str", "labSubnetName": "str", "resourceId": "str"}], + "createdDate": "2020-02-20 00:00:00", + "description": "str", + "externalProviderResourceId": "str", + "externalSubnets": [{"id": "str", "name": "str"}], + "id": "str", + "location": "str", + "name": "str", + "provisioningState": "str", + "subnetOverrides": [ + { + "labSubnetName": "str", + "resourceId": "str", + "sharedPublicIpAddressConfiguration": { + "allowedPorts": [{"backendPort": 0, "transportProtocol": "str"}] + }, + "useInVmCreationPermission": "str", + "usePublicIpAddressPermission": "str", + "virtualNetworkPoolName": "str", + } + ], + "tags": {"str": "str"}, + "type": "str", + "uniqueIdentifier": "str", + }, + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_begin_delete(self, resource_group): + response = await ( + await self.client.virtual_networks.begin_delete( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + ).result() # call '.result()' to poll until service return final result + + # please add some check logic here by yourself + # ... + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_update(self, resource_group): + response = await self.client.virtual_networks.update( + resource_group_name=resource_group.name, + lab_name="str", + name="str", + api_version="2018-09-15", + ) + + # please add some check logic here by yourself + # ... diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/setup.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/setup.py index 999d485828ff..d7b9a71b5707 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/setup.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/setup.py @@ -1,10 +1,10 @@ #!/usr/bin/env python -#------------------------------------------------------------------------- +# ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for # license information. -#-------------------------------------------------------------------------- +# -------------------------------------------------------------------------- import re import os.path @@ -16,63 +16,70 @@ PACKAGE_PPRINT_NAME = "Dev Test Labs Management" # a-b-c => a/b/c -package_folder_path = PACKAGE_NAME.replace('-', '/') +package_folder_path = PACKAGE_NAME.replace("-", "/") # a-b-c => a.b.c -namespace_name = PACKAGE_NAME.replace('-', '.') +namespace_name = PACKAGE_NAME.replace("-", ".") # Version extraction inspired from 'requests' -with open(os.path.join(package_folder_path, 'version.py') - if os.path.exists(os.path.join(package_folder_path, 'version.py')) - else os.path.join(package_folder_path, '_version.py'), 'r') as fd: - version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', - fd.read(), re.MULTILINE).group(1) +with open( + ( + os.path.join(package_folder_path, "version.py") + if os.path.exists(os.path.join(package_folder_path, "version.py")) + else os.path.join(package_folder_path, "_version.py") + ), + "r", +) as fd: + version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', fd.read(), re.MULTILINE).group(1) if not version: - raise RuntimeError('Cannot find version information') + raise RuntimeError("Cannot find version information") -with open('README.md', encoding='utf-8') as f: +with open("README.md", encoding="utf-8") as f: readme = f.read() -with open('CHANGELOG.md', encoding='utf-8') as f: +with open("CHANGELOG.md", encoding="utf-8") as f: changelog = f.read() setup( name=PACKAGE_NAME, version=version, - description='Microsoft Azure {} Client Library for Python'.format(PACKAGE_PPRINT_NAME), - long_description=readme + '\n\n' + changelog, - long_description_content_type='text/markdown', - license='MIT License', - author='Microsoft Corporation', - author_email='azpysdkhelp@microsoft.com', - url='https://github.com/Azure/azure-sdk-for-python', + description="Microsoft Azure {} Client Library for Python".format(PACKAGE_PPRINT_NAME), + long_description=readme + "\n\n" + changelog, + long_description_content_type="text/markdown", + license="MIT License", + author="Microsoft Corporation", + author_email="azpysdkhelp@microsoft.com", + url="https://github.com/Azure/azure-sdk-for-python", keywords="azure, azure sdk", # update with search keywords relevant to the azure service / product classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'License :: OSI Approved :: MIT License', + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "License :: OSI Approved :: MIT License", ], zip_safe=False, - packages=find_packages(exclude=[ - 'tests', - # Exclude packages that will be covered by PEP420 or nspkg - 'azure', - 'azure.mgmt', - ]), + packages=find_packages( + exclude=[ + "tests", + # Exclude packages that will be covered by PEP420 or nspkg + "azure", + "azure.mgmt", + ] + ), include_package_data=True, package_data={ - 'pytyped': ['py.typed'], + "pytyped": ["py.typed"], }, install_requires=[ - "msrest>=0.7.1", - "azure-common~=1.1", - "azure-mgmt-core>=1.3.2,<2.0.0", - "typing-extensions>=4.3.0; python_version<'3.8.0'", + "isodate>=0.6.1", + "typing-extensions>=4.6.0", + "azure-common>=1.1", + "azure-mgmt-core>=1.3.2", ], - python_requires=">=3.7" + python_requires=">=3.8", ) diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/conftest.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/conftest.py index 6ab86de70dae..4e3819d2abd2 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/conftest.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/conftest.py @@ -1,59 +1,35 @@ +# 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. -# +# 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 os -import platform import pytest -import sys - from dotenv import load_dotenv - -from devtools_testutils import test_proxy, add_general_regex_sanitizer, remove_batch_sanitizers -from devtools_testutils import add_header_regex_sanitizer, add_body_key_sanitizer - -# Ignore async tests for Python < 3.5 -collect_ignore_glob = [] -if sys.version_info < (3, 5) or platform.python_implementation() == "PyPy": - collect_ignore_glob.append("*_async.py") +from devtools_testutils import ( + test_proxy, + add_general_regex_sanitizer, + add_body_key_sanitizer, + add_header_regex_sanitizer, +) load_dotenv() + +# aovid record sensitive identity information in recordings @pytest.fixture(scope="session", autouse=True) def add_sanitizers(test_proxy): - subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") - tenant_id = os.environ.get("AZURE_TENANT_ID", "00000000-0000-0000-0000-000000000000") - client_id = os.environ.get("AZURE_CLIENT_ID", "00000000-0000-0000-0000-000000000000") - client_secret = os.environ.get("AZURE_CLIENT_SECRET", "00000000-0000-0000-0000-000000000000") - add_general_regex_sanitizer(regex=subscription_id, value="00000000-0000-0000-0000-000000000000") - add_general_regex_sanitizer(regex=tenant_id, value="00000000-0000-0000-0000-000000000000") - add_general_regex_sanitizer(regex=client_id, value="00000000-0000-0000-0000-000000000000") - add_general_regex_sanitizer(regex=client_secret, value="00000000-0000-0000-0000-000000000000") + devtestlabs_subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + devtestlabs_tenant_id = os.environ.get("AZURE_TENANT_ID", "00000000-0000-0000-0000-000000000000") + devtestlabs_client_id = os.environ.get("AZURE_CLIENT_ID", "00000000-0000-0000-0000-000000000000") + devtestlabs_client_secret = os.environ.get("AZURE_CLIENT_SECRET", "00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=devtestlabs_subscription_id, value="00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=devtestlabs_tenant_id, value="00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=devtestlabs_client_id, value="00000000-0000-0000-0000-000000000000") + add_general_regex_sanitizer(regex=devtestlabs_client_secret, value="00000000-0000-0000-0000-000000000000") + add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]") add_header_regex_sanitizer(key="Cookie", value="cookie;") add_body_key_sanitizer(json_path="$..access_token", value="access_token") - - # Remove the following sanitizers since certain fields are needed in tests and are non-sensitive: - # - AZSDK3493: $..name - remove_batch_sanitizers(["AZSDK3493"]) diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_global_schedules_operations_async_test.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_global_schedules_operations_async_test.py new file mode 100644 index 000000000000..234e0ca78676 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_global_schedules_operations_async_test.py @@ -0,0 +1,36 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.live_test_only +class TestDevTestLabsGlobalSchedulesOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_subscription(self, resource_group): + response = self.client.global_schedules.list_by_subscription() + result = [r async for r in response] + assert response + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_resource_group(self, resource_group): + response = self.client.global_schedules.list_by_resource_group( + resource_group_name=resource_group.name, + ) + result = [r async for r in response] + assert result == [] diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_global_schedules_operations_test.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_global_schedules_operations_test.py new file mode 100644 index 000000000000..2ea9eb644f9a --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_global_schedules_operations_test.py @@ -0,0 +1,35 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.live_test_only +class TestDevTestLabsGlobalSchedulesOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_subscription(self, resource_group): + response = self.client.global_schedules.list_by_subscription() + result = [r for r in response] + assert response + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_resource_group(self, resource_group): + response = self.client.global_schedules.list_by_resource_group( + resource_group_name=resource_group.name, + ) + result = [r for r in response] + assert result == [] diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_labs_operations_async_test.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_labs_operations_async_test.py new file mode 100644 index 000000000000..853f109e047c --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_labs_operations_async_test.py @@ -0,0 +1,36 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.live_test_only +class TestDevTestLabsLabsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_subscription(self, resource_group): + response = self.client.labs.list_by_subscription() + result = [r async for r in response] + assert response + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list_by_resource_group(self, resource_group): + response = self.client.labs.list_by_resource_group( + resource_group_name=resource_group.name, + ) + result = [r async for r in response] + assert result == [] diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_labs_operations_test.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_labs_operations_test.py new file mode 100644 index 000000000000..63ed122dac05 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_labs_operations_test.py @@ -0,0 +1,35 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.live_test_only +class TestDevTestLabsLabsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_subscription(self, resource_group): + response = self.client.labs.list_by_subscription() + result = [r for r in response] + assert response + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list_by_resource_group(self, resource_group): + response = self.client.labs.list_by_resource_group( + resource_group_name=resource_group.name, + ) + result = [r for r in response] + assert result == [] diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_provider_operations_operations_async_test.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_provider_operations_operations_async_test.py new file mode 100644 index 000000000000..be5e83dcf099 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_provider_operations_operations_async_test.py @@ -0,0 +1,27 @@ +# 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 pytest +from azure.mgmt.devtestlabs.aio import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer +from devtools_testutils.aio import recorded_by_proxy_async + +AZURE_LOCATION = "eastus" + + +@pytest.mark.live_test_only +class TestDevTestLabsProviderOperationsOperationsAsync(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient, is_async=True) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy_async + async def test_list(self, resource_group): + response = self.client.provider_operations.list() + result = [r async for r in response] + assert result diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_provider_operations_operations_test.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_provider_operations_operations_test.py new file mode 100644 index 000000000000..98ebe0321ec3 --- /dev/null +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_dev_test_labs_provider_operations_operations_test.py @@ -0,0 +1,26 @@ +# 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 pytest +from azure.mgmt.devtestlabs import DevTestLabsClient + +from devtools_testutils import AzureMgmtRecordedTestCase, RandomNameResourceGroupPreparer, recorded_by_proxy + +AZURE_LOCATION = "eastus" + + +@pytest.mark.live_test_only +class TestDevTestLabsProviderOperationsOperations(AzureMgmtRecordedTestCase): + def setup_method(self, method): + self.client = self.create_mgmt_client(DevTestLabsClient) + + @RandomNameResourceGroupPreparer(location=AZURE_LOCATION) + @recorded_by_proxy + def test_list(self, resource_group): + response = self.client.provider_operations.list() + result = [r for r in response] + assert result diff --git a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_mgmt_devtestlabs.py b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_mgmt_devtestlabs_test.py similarity index 69% rename from sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_mgmt_devtestlabs.py rename to sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_mgmt_devtestlabs_test.py index ed2fcbdbd242..bd8b4b5b4af2 100644 --- a/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_mgmt_devtestlabs.py +++ b/sdk/devtestlabs/azure-mgmt-devtestlabs/tests/test_mgmt_devtestlabs_test.py @@ -1,4 +1,4 @@ -# coding: utf-8 +# coding: utf-8 # ------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. @@ -6,28 +6,23 @@ # license information. # -------------------------------------------------------------------------- import unittest - +import pytest import azure.mgmt.devtestlabs from devtools_testutils import AzureMgmtRecordedTestCase, ResourceGroupPreparer, recorded_by_proxy +@pytest.mark.live_test_only class TestMgmtDevTestLabs(AzureMgmtRecordedTestCase): def setup_method(self, method): - self.client = self.create_mgmt_client( - azure.mgmt.devtestlabs.DevTestLabsClient - ) + self.client = self.create_mgmt_client(azure.mgmt.devtestlabs.DevTestLabsClient) @ResourceGroupPreparer() @recorded_by_proxy def test_devtestlabs(self, resource_group, location): - lab_name = self.get_resource_name('pylab') + lab_name = self.get_resource_name("pylab") - async_lab = self.client.labs.begin_create_or_update( - resource_group.name, - lab_name, - {'location': location} - ) + async_lab = self.client.labs.begin_create_or_update(resource_group.name, lab_name, {"location": location}) lab = async_lab.result() assert lab.name == lab_name @@ -35,11 +30,7 @@ def test_devtestlabs(self, resource_group, location): self.client.labs.get(resource_group.name, lab_name) # update - BODY = { - "properties": { - "labStorageType": "Premium" - } - } + BODY = {"properties": {"labStorageType": "Premium"}} self.client.labs.update(resource_group.name, lab_name, BODY) # delete @@ -48,5 +39,5 @@ def test_devtestlabs(self, resource_group, location): # ------------------------------------------------------------------------------ -if __name__ == '__main__': +if __name__ == "__main__": unittest.main()